Making allegro5 project with CLion - c++

Few days ago I downloaded clion to make a school project in C++ and Allegro5. First I used allegro installed with homebrew but it wasn't working so I compiled it by myself. Since I've never worked with CMake before it took me some time to include the libs and compile the project but I managed to do it. The problem is that when I try to run it it throws an error:
dyld: Symbol not found: __al_mangled_main
Referenced from: /usr/local/lib/liballegro_main.5.0.dylib
Expected in: flat namespace
in /usr/local/lib/liballegro_main.5.0.dylib
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(arkanoid)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES classes/main.cpp classes/ball.cpp classes/ball.h classes/block.cpp classes/block.h)
add_executable(arkanoid ${SOURCE_FILES})
INCLUDE_DIRECTORIES( allegro/5.0.11/include )
LINK_DIRECTORIES( allegro/5.0.11/lib )
TARGET_LINK_LIBRARIES(arkanoid allegro_acodec
allegro_audio
allegro_color
allegro_dialog
allegro_image
allegro_main
allegro_memfile
allegro_physfs
allegro_primitives
allegro_ttf
allegro_font
allegro)
And for now my main.cpp looks like this:
#include <iostream>
#include <allegro5/allegro.h>
using namespace std;
int main() {
al_init();
return 0;
}
I'm trying to build this project on OSX. I've searched for 2 days for the solution to my problem but with no results. Not many people are using CLion and even less use it with allegro5. Could anyone have a clue what this error even mean?

Ok this one blew my mind. I don't know why I found solution only after asking on stackoverflow but I'm posting it for someone who might encounter simillar problem to mine. Change your main declaration from
int main()
to
int main(int argc, char **argv)
and that's it. Really.

Related

glfwInit() causes segmentation fault with exit code -1073741515 (0xc0000135)

I have been trying to get one my older projects to work which uses some OpenGL code. I am unable to produce a working executable. All that happens is, just by calling glfwInit(), is a segmentation fault:
My best guess is that it somehow doesnt use/find the glfw dll i am trying to use.
Let me explain my current setup:
I have installed glfw using msys2:
pacman -S mingw-w64-x86_64-glfw
I have created a glad header and source file
I wrote a simple cmake-file (which also used to work 2 years ago)
cmake_minimum_required(VERSION 3.23)
project(2DGameEngine)
find_package(glfw3 3.3 REQUIRED)
find_package(OpenGL REQUIRED)
set(CMAKE_CXX_STANDARD 23)
file(GLOB_RECURSE SRCS src/*.cpp src/*.c)
add_executable(2DGameEngine ${SRCS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow")
target_link_libraries(2DGameEngine glfw)
target_link_libraries(2DGameEngine OpenGL::GL)
I used the simplest example I could find:
#include "glad.h"
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
// glfw: initialize and configure
// ------------------------------
if(!glfwInit()){
std::cout << "error" << std::endl;
exit(1);
}
return 0;
}
Yet I am unable to get rid of the segmentation fault when calling glfwInit(). I assume it has to do with some .dll missing but I have no idea how I could check this. I am very happy for any help.
0xc0000135 is the error you get when your Windows OS could not find a required dll when executing your program. There is a handy site that decodes these types of errors here: https://james.darpinian.com/decoder/?q=0xc0000135
Use this program: https://github.com/lucasg/Dependencies to figure out what dll can not be found and then put that dll in the same folder as the executable or edit your OS PATH environment variable to contain the folder which has that dll.
Here is a good article on how to set the OS PATH environment variable: https://www.computerhope.com/issues/ch000549.htm
There are several other options contained in this Microsoft document which explains how and where your OS searches for dlls: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications

CLion C++17 boost: No member named xxx in namespace

I'm setting up a C++17 + boost 1.76.0 project in Clion 2018.3, with this minimal code:
#include <boost/asio/ip/tcp.hpp>
int main(int argc, char **argv)
{
auto const address = boost::asio::ip::make_address(argv[1]);
return 0;
}
In my CMakeLists.txt I have correctly setup the C++ version:
add_definitions(-std=c++17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
And the project compiles and run fine. But Clion shows the following error on the make_address line:
No member named 'make_address' in namespace 'boost::asio::ip'
CTRL-hover on the method name correctly shows the doc, and CTRL-click correctly opens the header file.
Are we supposed to do something else to tel Clion which C++ version are we using?
Looks like the IDE and compiler don't agree in the version of boost. These functions are not specific toi a language version, but I think were introduced in a relatively recent Boostt release
It turned out that I had 2 Boost versions installed on the system, one shipped with ROS (I didn't know that) and v1.76.0 that I compiled to get boost::asio. Looks like Clion was using the one of ROS which older.
Uninstalling v1.76.0 system-wide and adding it back as a header library in the project fixed these false errors, though Clion now takes forever to anaylise the code (despite I excluded the libs folder). Using only the version shipped with ROS would be the best solution for someone not needed the latest additions of Boost (but I do).

CMake: DLL's Missing

I'm new to CMake and after a week of endless errors I'm at my wit's end.
main.cpp
#include <tox/tox.h>
int main(int argc, char **argv) {
Tox* tox = tox_new(NULL, NULL);
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
Project(toxtest)
add_library(toxcore SHARED IMPORTED)
set_target_properties(toxcore PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/c-toxcore/include"
IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/c-toxcore/_build/Debug/toxcore.lib"
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/c-toxcore/_build/Debug/toxcore.dll"
)
set(BINARY_NAME "toxtest-bin")
add_executable(${BINARY_NAME} main.cpp)
target_link_libraries(${BINARY_NAME} PUBLIC toxcore)
Introduction:
My C++ executable depends on a C-library called toxcore, toxcore depends on two other C-libraries called pthread-win32 and libsodium.
I have compiled the toxcore library with the following flags, to solve a unresolved external symbol error (Not sure if this is the right way):
cmake .. -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DBUILD_SHARED_LIBS=TRUE
I build my executable successfully but now it complains about missing DLL's:
toxcore.dll, libsodium.dll, pthreadVC2.dll
With my patience running out:
I dumped the DLL's into the directory with the executable, and now I got Application Error:
The application was unable to start correctly (0xc000007b)
How do I this properly?
I want to solve the Application Error, and let the executable find the DLL's in their respective directories.
PS: Before anyone marks my question as duplicate.
I have looked thru and tried stackoverflow answers which were not sufficient in detail/clarity for a beginner like me. I need someone to give me a more tailored answer and tell me if my steps are in line with the current best practices.

OpenCV cannot find libraries [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I am trying to read an image in OpenCV, like this:
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main (int argv, char **argc)
{
Mat image = imread("Foam_Image.jg", CV_LOAD_IMAGE_GRAYSCALE);
return 0;
}
But I get the following error:
undefined reference to cv::imread(cv::String const&, int)
It seems that OpenCV cannot find the libraries I included, maybe because I didn't link them correctly, or maybe there are some libraries missing. Does anyone know how to look for missing libraries or how to link the libraries in OpenCV?
If your operating system is any UNIX which has CMake, then it would be better for you to write a CMakelists.txt file as follows
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
And just use
cmake .
make
./DisplayImage
to execute the program.
you can install CMake from the official repositories using your package manager
In case your operating system is Windows, install CMake and set compiler options as Visual Studio (your version). Also add the OpenCV path to your system path, if not already done.
More instructions here :
http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html

making boost work with cmake ( fatal error: boost/smart_ptr.hpp: No such file or directory )

After digging for hours on this, I finally need some expert help.
I am new to cmake and trying to port my Visual Studio 2008 project to cmake.
My project uses opencv, qt and boost libraries.
Now I have managed to run simple cmake examples with opencv and qt but I am stuck with boost.
The bottleneck is this: CMake finds the correct boost version, finds the libraries and gives no error while configuration.
But when I try to build the project using make, it gives me:
" fatal error: boost/smart_ptr.hpp: No such file or directory"
Assuming the configuration is done right, cmake should be able to find the boost include directories.
I have set BOOST_ROOT to the correct boost root directory and that's why configuration does not give errors. But what happens while running make? Am I missing something simple here? Need help desperately...
I am sorry if this is a stupid question.
Here's my CMakeLists.txt file:
cmake_minimum_required( VERSION 2.6 )
project (CMakeBoostTutorial)
find_package( Boost 1.46.1 COMPONENTS date_time REQUIRED)
link_directories ( ${Boost_LIBRARY_DIRS} )
include_directories ( ${Boost_INCLUDE_DIRS} )
add_executable ( helloworld helloworld.cc )
target_link_libraries (
helloworld
${Boost_LIBRARIES}
)
And here's my helloworld.cc:
#include <iostream>
#include <stdlib.h>
#include <boost/smart_ptr.hpp>
using namespace std;<br/>
int main(int argc, char *argv[]){
cout<<"Hello World";
return 0;
}
PS: This compiles and runs fine if I remove the #include <boost/smart_ptr.hpp> line