How to add allegro Library in Clion and CMake? - c++

I am trying to compile my game project using Clion IDE but I have a problem when porting allegro 5. I get this error:
main.cpp:2:10: fatal error: 'allegro/allegro.h' file not found
#include <allegro/allegro.h>
My CMakeLists is:
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/include )
LINK_DIRECTORIES( /usr/local/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})
Just I want to ask how can I add external Library allegro to Clion?

when you install allegro using homebrew link
use this cmake to compile clion project
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/include )
LINK_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})

Related

C++: static link not found

I make a libtest_lib.a file with cmake.
cmake_minimum_required(VERSION 3.8)
project(test)
set(CMAKE_CXX_STANDARD 98)
set(SOURCE_FILES library.cpp library.h)
add_library(test_lib ${SOURCE_FILES})
then in my executable C++ project ,I include the #include "library.h"
and the CMakeList.txt:
cmake_minimum_required(VERSION 3.8)
project(study)
set(CMAKE_CXX_STANDARD 98)
set(SOURCE_FILES main.cpp)
add_executable(study ${SOURCE_FILES})
target_link_libraries(study libtest_lib.a) //libtest_lib.a file under the project path
but it fails.
/Users/bin381/CLionProjects/study/main.cpp:1:10: fatal error: 'library.h' file not found
Please add the include directories as mentioned in the documentation : https://cmake.org/cmake/help/v3.0/command/include_directories.html
Otherwise cmake will not be able to find where to look in for include files.

C++ .exe with .dll not running outside of CLion

The program runs just fine when started from inside CLion although it is refusing to run by double clicking the .exe with this error being shown when I try to run it:
The procedure entry point _ZNKSt7__cxx1112basic_stringlcSt11char_traitslcESalcEE12find_last_ofEPKcyy could not be located in the dynamic link library C:\Users\steppers\projects\cyan\bin\libcyan_engine.dll.
It looks to me like an issue with a standard lib or something judging by the basic_string bit but I'm at a complete loss here now.
Here is my root CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(cyan_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_subdirectory(engine)
include_directories(engine/include)
set(SOURCE_FILES src/main.cpp)
add_executable(cyan_test ${SOURCE_FILES})
target_link_libraries(cyan_test cyan_engine)
And the engine subdirectory's:
cmake_minimum_required(VERSION 3.6)
project(cyan_engine)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_subdirectory(lib/glfw-3.2.1)
include_directories(lib/glfw-3.2.1/include)
add_definitions("-fPIC")
add_subdirectory(lib/g3log-1.2)
include_directories(lib/g3log-1.2/src)
include_directories(include)
set(SOURCE_FILES <src files here>)
add_library(cyan_engine SHARED ${SOURCE_FILES})
target_link_libraries(cyan_engine glfw g3logger)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(cyan_engine ${OPENGL_gl_LIBRARY})
Any help would be greatly appreciated.

Building wxWidgets 3.1.0 on CLion (Ubuntu)

I am currently trying to build wxWidgets-3.1.0 on a CLion 1.3 project. I use Ubuntu 16.04 (64 bit). Basically, I edited the CMakeLists.txt file like this:
cmake_minimum_required(VERSION 3.5)
project(WxProva)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules"
${CMAKE_MODULE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WxProva ${SOURCE_FILES})
find_package(wxWidgets)
include_directories(${wxWidgets_INCLUDE_DIRS})
target_link_libraries(WxProva ${wxWidgets_LIBRARIES})
The "External Libraries" section also shows me wxWidgets, but when it comes to write some lines on my main.cpp, everything related with the library seems to be unreachable by the compiler (it's all written in red, like an error). Anyway, if I try to compile, that's the result:
/home/federico/ClionProjects/WxProva/main.cpp:2:35: fatal error: wxWidgets-3.1.0/include: File o directory non esistente
compilation terminated.
Which is like "File or directory doesn't exists."
How can I fix this?
After some experiments here solution. You can just copy it and change some information and ready to build and run.
cmake_minimum_required(VERSION 3.7)
project(Your_Project_Name) //any name for your project
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_ROOT_DIR </usr/include/wx-3.0-unofficial>) // here I am giving where to search for wxwidgets library. it can be different for you
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(FirstC ${SOURCE_FILES})
target_link_libraries(FirstC ${wxWidgets_LIBRARIES})
For more Information read https://wiki.wxwidgets.org/CMake
Edit 1
Here you shouldn't even add some compile and link config (wx-config --cxxflags and wx-config --libs) as it is necessary in NetBeans
Here is example configuration for macOS 10.14.4 (Mojave) and CLion 2019.1
(/usr/local is folder where I installed wxWidgets)
cmake_minimum_required(VERSION 3.14)
project(wx1Test)
set(CMAKE_CXX_STANDARD 14)
set(wxWidgets_ROOT_DIR </usr/local/include/wx-3.1>)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(wx1Test ${SOURCE_FILES})
target_link_libraries(wx1Test ${wxWidgets_LIBRARIES})

Using OpenCv with CLion

Hey im trying to use the OpenCV Lib on elementary OS (based on Ubuntu).
I followed this tutorial:
https://www.youtube.com/watch?v=i1K9rXiei9I
I added this lines to the CmakeList.txt:
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(myOpenCVTest ${OpenCV_LIBS})
But when i build the project it fails with some errors like:
/usr/bin/ld: cannot find -lopencv_core
...
Can anyone help me???
I solved the problem.
First I deleted all old OpenCV files and installations.
After that I followed this guide to install OpenCV and all required packages.
And now everything is working with this CmakeList.txt:
cmake_minimum_required(VERSION 2.8.4)
project(OpenCVTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )
I had to forcefully declare OpenCV_FOUND 1 in the cmake file, The whole file looks like :
cmake_minimum_required(VERSION 3.3)
project(testing)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(OpenCV_FOUND 1)
find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(testing ${SOURCE_FILES})
target_link_libraries(testing ${OpenCV_LIBS})
(following our chat in the comments section)
I am not sure what video did you use for the installation, but assuming you used cmake based installation you usually run make followed by sudo make install that copies everything to the right location
Alternatively you can add link_directories(home/Projects/opencv/opencv-3/build/lib/)
and include_directories((home/Projects/opencv/opencv-3/include/) to your CMakeLists.txt

Linking c++ library with CMake

I'm tring to use CMS and cannot link libraries that i compiled on my linux. My CMakeLists.txt:
project(region_algorithm)
SET_TARGET_PROPERTIES(PROPERTIES LINKER_LANGUAGE CXX)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
INCLUDE_DIRECTORIES(
/usr/local/include/activemq-cpp-3.8.3
/usr/local/apr/include/apr-1)
link_libraries(
/usr/local/lib/libactivemq-cpp.a
/usr/local/apr/lib/libapr-1.a)
When i'm building project i got errors like:
regionalgorithmconsumer.cpp:-1: error: undefined reference to
`decaf::util::concurrent::CountDownLatch::CountDownLatch(int)'