I've been trying to get SDL2 to link with my project but I think my cmake file is no good. I get this error
====================[ Build | Chip_8_Interpreter | Debug ]======================
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" --build "D:\Dropbox\Programming\Chip-8 Interpreter\cmake-build-debug" --target Chip_8_Interpreter -- -j 4
[ 50%] Linking CXX executable Chip_8_Interpreter.exe
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Chip_8_Interpreter.exe] Error 1
CMakeFiles\Chip_8_Interpreter.dir\build.make:87: recipe for target 'Chip_8_Interpreter.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/Chip_8_Interpreter.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Chip_8_Interpreter.dir/rule] Error 2
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/rule' failed
mingw32-make.exe: *** [Chip_8_Interpreter] Error 2
Makefile:117: recipe for target 'Chip_8_Interpreter' failed
And currently my CMakeLists.txt looks like this
cmake_minimum_required(VERSION 3.14)
project(Chip_8_Interpreter)
set(CMAKE_CXX_STANDARD 14)
# include cmake/FindSDL2.cmake
set(SDL2_PATH "C:\\SDL2-2.0.12\\i686-w64-mingw32")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(Chip_8_Interpreter main.cpp)
target_link_libraries(Chip_8_Interpreter ${SDL2_LIBRARY} -lmingw32 -lSDL2main -lSDL2 -mwindows)
And my main.cpp is just the basic SDL example. I've also recently installed MinGW and SDL2, so they should both be the newest stable release.
Related
I am currently trying to install the SDL library with C++ and Clion. I watched many youtube videos and googled the errors but still cannot find a way to fix this error.
"C:\Program Files\JetBrains\CLion 2021.1.2\bin\cmake\win\bin\cmake.exe" --build D:\Programing\C++\School\HackClub\Day2\cmake-build-debug --target Day2 -- -j 6
[ 50%] Linking CXX executable Day2.exe
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\Day2.dir\build.make:95: Day2.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/Day2.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/Day2.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:123: Day2] Error
Here is my CMAKE file.
project(Day2)
set(CMAKE_CXX_STANDARD 14)
set(SDL2_INCLUDE_DIR D:\\Programing\\C++\\libs\\SDL\\include)
set(SDL2_LIBRARY D:\\Programing\\C++\\libs\\SDL\\lib\\x86)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY})
target_link_libraries(${PROJECT_NAME} SDL2main SDL2)
I am receiving following error while executing a program in clion.
"C:\Program Files\JetBrains\CLion 2019.2.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\two43\CLionProjects\cse\cmake-build-debug --target cse -- -j 2
[ 25%] Linking CXX executable cse.exe
CMakeFiles\cse.dir\build.make:114: recipe for target 'cse.exe' failed
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\cse.dir/objects.a(lecture-2.cpp.obj): in function `main':
C:/Users/two43/CLionProjects/cse/lecture-2.cpp:24: multiple definition of `main'; CMakeFiles\cse.dir/objects.a(lecture-1.cpp.obj):C:/Users/two43/CLionProjects/cse/lecture-1.cpp:19: first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [cse.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/cse.dir/all] Error 2
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/cse.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/cse.dir/rule] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/cse.dir/rule' failed
mingw32-make.exe: *** [cse] Error 2
Makefile:117: recipe for target 'cse' failed
Following is the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(cse)
set(CMAKE_CXX_STANDARD 17)
add_executable(cse main.cpp lecture-1.cpp lecture-2.cpp)
You are compiling two files, cse/lecture-1.cpp and cse/lecture-2.cpp. Both contain a main function. You cannot build a single executable with multiple main functions.
Make them separate executables by using add_executable two times in your CMake definitions. I would show you how if you provided your CMake definitions.
Edit: Based on your CMake definitions, use
cmake_minimum_required(VERSION 3.15)
project(cse)
set(CMAKE_CXX_STANDARD 17)
add_executable(lecture-1 main.cpp lecture-1.cpp)
add_executable(lecture-2 main.cpp lecture-2.cpp)
This assumes main.cpp, despite its name, does not contain another main function. If it does, you'll need a separate add_executable for it too.
I want to use a LIDAR and their SDK has two folders which are "src" and includes. src, contain few CPP files whereas include contains the header file. Now in my main.cpp I have to import one header file that contains all the necessary functions to work with the Lidar.
Now using CMakelists.txt I was trying to add them but it shows error.
====================[ Build | delta_lidar_node | Debug ]========================
"C:\Program Files\JetBrains\CLion 2019.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\kazia\OneDrive\Desktop\cpp\cmake-build-debug --target delta_lidar_node -- -j 2
Scanning dependencies of target delta_lidar_node
[ 50%] Building CXX object CMakeFiles/delta_lidar_node.dir/main.cpp.obj
[100%] Linking CXX executable delta_lidar_node.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lrt
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
CMakeFiles\delta_lidar_node.dir\build.make:85: recipe for target 'delta_lidar_node.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/delta_lidar_node.dir/all' failed
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/delta_lidar_node.dir/rule' failed
mingw32-make.exe[3]: *** [delta_lidar_node.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/delta_lidar_node.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/delta_lidar_node.dir/rule] Error 2
mingw32-make.exe: *** [delta_lidar_node] Error 2
Makefile:117: recipe for target 'delta_lidar_node' failed
here is my Cmakelists.txs
cmake_minimum_required(VERSION 2.8.3)
project(delta_lidar)
set(delta_lidar_SDK_PATH "./src/")
FILE(GLOB delta_lidar_SDK_SRC
"${delta_lidar_SDK_PATH}/src/*.cpp"
)
include_directories(
${delta_lidar_SDK_PATH}/include
${delta_lidar_SDK_PATH}/src
)
add_executable(delta_lidar_node main.cpp ${delta_lidar_SDK_SRC})
target_link_libraries(delta_lidar_node -lrt -lpthread)
I want to build an executable that includes all of libs that I used (opencv, dlib) so it can work on any computer.
Here is my current CMakeList.txt
cmake_minimum_required(VERSION 3.5.1)
project(adc_fr)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(/media/sf_dlib-19.9/dlib dlib_build)
FIND_PACKAGE(OpenCV REQUIRED)
set(SOURCE_FILES
FDetect.cpp
FDetect.h
FExtract.cpp
FExtract.h
main.cpp
)
add_executable(adc_fr ${SOURCE_FILES})
set_target_properties(adc_fr PROPERTIES LINK_FLAGS "-static")
target_link_libraries(adc_fr
${OpenCV_LIBS}
dlib
)
Here is the error I got when linking
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libwebp.so'
collect2: error: ld returned 1 exit status
CMakeFiles/adc_fr.dir/build.make:409: recipe for target 'adc_fr' failed
make[2]: *** [adc_fr] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/adc_fr.dir/all' failed
make[1]: *** [CMakeFiles/adc_fr.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I do have libwebp.a available in /usr/lib/x86_64-linux-gnu/
How can I force to use static libwebp.a instead of libwebp.so?
I did try to add #SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") but it still gave the same error.
Much appreciated!
How about this:
find_library(LIBWEBP_LOCATION libwebp.a)
target_link_libraries(adc_fr
${OpenCV_LIBS}
dlib
${LIBWEBP_LOCATION}
)
I have Clion IDE on Kubuntu 15.04. I have problem, when i build my application there is this problem :
/home/pierre/Bureau/CLion/bin/cmake/bin/cmake --build /home/pierre/.CLion12/system/cmake/generated/2a804d19/2a804d19/Debug --target WCPLauncher -- -j 4
Scanning dependencies of target WCPLauncher
[ 50%] Linking CXX executable WCPLauncher
/home/pierre/Qt5.0.2/5.0.2/gcc/lib/libQt5Widgets.so.5.0.2: error adding symbols: Fichier dans un mauvais format
collect2: error: ld returned 1 exit status
CMakeFiles/WCPLauncher.dir/build.make:97: recipe for target 'WCPLauncher' failed
make[3]: *** [WCPLauncher] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/WCPLauncher.dir/all' failed
make[2]: *** [CMakeFiles/WCPLauncher.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/WCPLauncher.dir/rule' failed
make[1]: *** [CMakeFiles/WCPLauncher.dir/rule] Error 2
Makefile:118: recipe for target 'WCPLauncher' failed
make: *** [WCPLauncher] Error 2
This is my cmake.txt :
cmake_minimum_required(VERSION 3.2)
project(WCPLauncher)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WCPLauncher ${SOURCE_FILES})
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
qt5_use_modules( WCPLauncher Core Widgets Gui )
Thanks !