I've been working on a project in CLion for quite some time now (over a month). All of a sudden, CLion will not build all of my files... When I run my program, my messages build looks like this:
Scanning dependencies of target main.cpp
[ 11%] Building CXX object CMakeFiles/main.cpp.dir/Custom_Types.cpp.o
[ 22%] Linking CXX executable ../bin/main.cpp
ld: library not found for -l*.cpp
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[3]: *** [../bin/main.cpp] Error 1
make[2]: *** [CMakeFiles/main.cpp.dir/all] Error 2
make[1]: *** [CMakeFiles/main.cpp.dir/rule] Error 2
make: *** [main.cpp] Error 2
Great... what the flippin fireworks is going on? This is what my CMake looks like...
cmake_minimum_required(VERSION 3.7)
project(Crazy_Sniper)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fpermissive")
find_package (OpenGL REQUIRED)
find_package (GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIRS})
file(GLOB SOURCE_FILES
*.cpp
*.h
)
add_executable(main.cpp ${SOURCE_FILES} Custom_Types.cpp)
target_link_libraries (main.cpp ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES}
mdl pthread)
Does anyone know what the problem is? I've looked through countless forums, and I cannot seem to find someone with a similar problem. Any help would be much appreciated.
Update! I've managed to get CLion to build my files, but main still does nothing... I try simply printing something out, and the console does nothing. I get an error code 11 for some reason...?
Thank you!
Related
im trying to link a static library (libglfw3.a). The library is place in my "lib" folder which is in the root directory of my project. I keep getting the error which can be found at the bottom. Hope someone can help me. Thanks in advance!
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(GLFWGLADSTUFF)
set(CMAKE_CXX_STANDARD 11)
set(SOURCES
src/main.cpp
src/glad.c
)
INCLUDE_DIRECTORIES(include)
add_executable(GLFWGLADSTUFF ${SOURCES})
target_include_directories(GLFWGLADSTUFF
PUBLIC src
PUBLIC include
)
target_link_libraries(GLFWGLADSTUFF
lib/libglfw3.a
)
Error:
Consolidate compiler generated dependencies of target GLFWGLADSTUFF
[ 33%] Linking CXX executable GLFWGLADSTUFF
ld: library not found for -llib/libglfw3.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GLFWGLADSTUFF] Error 1
make[1]: *** [CMakeFiles/GLFWGLADSTUFF.dir/all] Error 2
make: *** [all] Error 2
link_directories(lib)
target_link_libraries(GLFWGLADSTUFF glfw3)
should resolve your issue. CMake is not recognizing your path as a path, but as the library name.
target_link_libraries(GLFWGLADSTUFF
lib/libglfw3.a
)
Will not work. You can:
specify the linker path and the name to be linked (i.e. other answer)
or preferably, use an IMPORTED add_library. There is even nice cmake documentation on the topic.
I have a library compiled as a single file that I'm trying to link with cmake but haven't been able to cobble together something that works using existing examples that should be related, eg.
CMake link an external library
Cmake linking external libraries
What I have so far:
cmake_minimum_required(VERSION 3.17)
project(atem)
set(CMAKE_CXX_STANDARD 14)
set(BMD_API_LIB "BMDSwitcherAPI")
set(BMD_API_PATH "/Library/Application Support/Blackmagic Design/Switchers/BMDSwitcherAPI.bundle/Contents/MacOS/")
find_library(BMDSwitcherAPI ${BMD_API_LIB} PATHS ${BMD_API_PATH})
add_executable(atem main.cpp BMDSwitcherAPIDispatch.cpp)
target_link_libraries(atem ${BMDSwitcherAPI})
The files main.cpp and BMDSwitcherAPIDispatch.cpp exist in the same directory. Building says that the file for the library can't be found, but the binary for the library file for ${BMD_API_LIB} cannot be found, but it is definitely at the path given in ${BMD_API_PATH}.
I'm not sure where to go from here.
Edit: added entire error message
====================[ Build | atem | Debug ]====================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/user/Code/atem/cmake-build-debug --target atem -- -j 9
[ 33%] Linking CXX executable atem
ld: library not found for -lBMDSwitcherAPI
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [atem] Error 1
make[2]: *** [CMakeFiles/atem.dir/all] Error 2
make[1]: *** [CMakeFiles/atem.dir/rule] Error 2
make: *** [atem] Error 2
This may not be helpful to anyone else because it was so specific to the one library I was using, but here it is anyway.
cmake_minimum_required(VERSION 3.17)
project(atem)
set(CMAKE_CXX_STANDARD 14)
find_library(CoreFoundation_Library CoreFoundation)
mark_as_advanced(CoreFoundation_Library)
set(
SWITCHERS_SDK_INCLUDE_DIR
/Applications/Blackmagic\ ATEM\ Switchers/Developer\ SDK/Mac\ OS\ X/include/
)
add_executable(
atem
atem/main.cpp
${SWITCHERS_SDK_INCLUDE_DIR}/BMDSwitcherAPIDispatch.cpp
)
target_include_directories(atem PRIVATE ${SWITCHERS_SDK_INCLUDE_DIR})
target_link_libraries(atem ${CoreFoundation_Library})
I'm working on a simple tutorial from here: https://lazyfoo.net/tutorials/SDL/02_getting_an_image_on_the_screen/index.php
My initial program did not do any image loading. It just showed a screen and went away. Everything worked fine. Here is my initial CMakeLists.txt file:
cmake_minimum_required(VERSION 3.7)
project(01_hello_world)
set(CXX_STANDARD 17)
find_package(SDL2 REQUIRED)
add_executable(hello 01_hello_SDL.cpp)
target_include_directories(hello PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(hello ${SDL2_LIBRARIES})
Everything worked and compiled just fine. However, I then wanted to load a PNG image, which I thought would be a very easy. Googling led me to the SDL2 Image library, and the IMG_Load method. So I went ahead and installed libsdl2-image-dev, and my CMakeLists.txt file grew by two more lines::
set(SDL2IMAGE_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
set(SDL2IMAGE_LIBRARIES "/usr/lib/x86_64-linux-gnu/libSDL2_image.a")
However, just by using the IMG_Load method, the make command threw a whole bunch of library requirements: libtiff-dev, libpng-dev, libjpeg-dev, libwebp-dev. All this just to load a png file! So I went ahead and installed all those, and now my CMakeLists.txt file looks like this abomination (I used find_package where I could, and manually set variables where I couldn't):
cmake_minimum_required(VERSION 3.7)
project(01_hello_world)
set(CXX_STANDARD 17)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(SDL2 REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
find_package(TIFF REQUIRED)
set(SDL2IMAGE_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
set(SDL2IMAGE_LIBRARIES "/usr/lib/x86_64-linux-gnu/libSDL2_image.a")
set(WEBP_LIBRARIES "/usr/lib/x86_64-linux-gnu/libwebp.a")
add_executable(hello 01_hello_SDL.cpp)
target_include_directories(hello PRIVATE ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS})
target_link_libraries(hello ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${WEBP_LIBRARIES} ${TIFF_LIBRARIES} Threads::Threads)
At this point, when I make, I get this error:
[ 50%] Linking CXX executable hello
/usr/bin/ld: cannot find -l{TIFF_LIBRARIES}
collect2: error: ld returned 1 exit status
CMakeFiles/hello.dir/build.make:98: recipe for target 'hello' failed
make[2]: *** [hello] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/hello.dir/all' failed
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I've been googling for hours. Can someone provide a light in this darkness?
Also is this the correct approach to working with sdl + cmake?
set(SDL2IMAGE_LIBRARIES "/usr/lib/x86_64-linux-gnu/libSDL2_image.a")
It seems like you aren't dynamically linking SDL2_image to your program.
I don't know how to change it in CMake,but you could compile your program utilizing this pattern:
g++ your_program.cpp -o your_program -lSDL2 -lSDL2_image
You may also utilize a Makefile like this one:
OBJS = your_program.cpp
OBJ_NAME = your_program_output
all:
g++ $(OBJS) -o $(OBJ_NAME) -lSDL2 -lSDL2_image # don't forget about replacing the four spaces by a tab character
One last thing, lazy foo has a tutorial teaching how to install and set up the SDL2_image library on linux utilizing an IDE (Code::Blocks) or not (command lines and Makefiles).
http://lazyfoo.net/tutorials/SDL/06_extension_libraries_and_loading_other_image_formats/linux/index.php
Recently I have acquired the "curses.h" and built the PDCurses "pdcurses.a" library file thanks to:
https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-pdcurses
package. I also have prepared cmake files:
# pdcurses-config.cmake
set(PDCURSES_LIBDIR "${PROJECT_SOURCE_DIR}/lib")
set(PDCURSES_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/include")
set(PDCURSES_LIBRARIES "-L${PDCURSES_LIBDIR} -lpdcurses -static -Wall -Werror")
string(STRIP "${PDCURSES_LIBRARIES}" PDCURSES_LIBRARIES)
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MatrixAlgebra)
set(CMAKE_CXX_STANDARD 11)
set(PDCURSES_DIR "${PROJECT_SOURCE_DIR}/cmake")
find_package(PDCURSES REQUIRED)
include_directories(${PDCURSES_INCLUDE_DIRS})
set(SOURCE_FILES src/main.cpp)
add_executable(MatrixAlgebra ${SOURCE_FILES})
target_link_libraries(MatrixAlgebra ${PDCURSES_LIBRARIES})
Unfortunately I'm unable to link a simple "Hello World!" console program because either I am getting this:
mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpdcurses
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: * [CMakeFiles\MatrixAlgebra.dir\build.make:97: MatrixAlgebra.exe] Error 1
mingw32-make.exe[2]: [CMakeFiles\Makefile2:67: CMakeFiles/MatrixAlgebra.dir/all] Error 2
mingw32-make.exe[1]: [CMakeFiles\Makefile2:79: CMakeFiles/MatrixAlgebra.dir/rule] Error 2
mingw32-make.exe: * [Makefile:117: MatrixAlgebra] Error 2
or this (when I change "pdcurses.a" to "libpdcurses.a"):
Process finished with exit code -1073741515 (0xC0000135)
I simply don't know what to do to make it proceed without problems.
you shouldn't treat target_link_libraries() like commandline to feed it with parameters like -Wall
I don't know pdcurses, but when find_package finds that lib you should probably use something like:
target_link_libraries(MatrixAlgebra pdcurses::pdcurses)
I'm trying to link my project with google C++ testing framework. I use Mac OS X El Capitan and I have installed test library in the default path.
lib:
/usr/local/lib/libgtest_main.a
/usr/local/lib/libgtest.a
include (for headers):
/usr/local/include/gtest
I created a new CLion (2016.1.1) project a this is the CMakeList.txt which should include the lib.
cmake_minimum_required(VERSION 3.5)
project(GoogleTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(GoogleTest ${SOURCE_FILES})
target_link_libraries(GoogleTest gtest gtest_main)
This is the result:
Scanning dependencies of target GoogleTest
[ 50%] Building CXX object CMakeFiles/GoogleTest.dir/main.cpp.o
[100%] Linking CXX executable GoogleTest
ld: library not found for -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GoogleTest] Error 1
make[1]: *** [CMakeFiles/GoogleTest.dir/all] Error 2
make: *** [all] Error 2
How can I fix this? Thanks in advance
It looks like /usr/local/lib is not in the compiler's library path list. Try specifying the full path for the libraries in target_link_libraries.
target_link_libraries(GoogleTest /usr/local/lib/libgtest.a /usr/local/lib/libgtest_main.a)