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.
Related
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.
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 have a project in CLion in which I need to include a library from the Windows 8.1 SDK, so I attempted to use CMake to link it.
I don't have any .so or .dll, but .lib (or directly the .h file).
Specifically, this library is dsound.h.
I tried to look for related questions, but none of the solutions I found works for me: how can I do it?
My current CMakeLists.txt is
cmake_minimum_required(VERSION 3.7)
project(Project)
set(CMAKE_CXX_STANDARD 11)
include_directories(${WinSDK})
set(SOURCE_FILES main.cpp file1.h file1.cpp)
add_executable(Project ${SOURCE_FILES})
target_link_libraries(Project ${WinSDK})
where WinSDK is the variable containing the location of the Windows SDK.
The error I get is the following:
[ 33%] Building CXX object CMakeFiles/Project.dir/main.cpp.obj
[ 66%] Building CXX object CMakeFiles/Project.dir/soundclass.cpp.obj
In file included from C:\projectPath\soundclass.cpp:4:0:
C:\projectPath\soundclass.h:21:24: fatal error: dsound.h: No such file or directory
In file included from C:\projectPath\main.cpp:5:0:
C:\projectPath\soundclass.h:21:24: fatal error: dsound.h: No such file or directory
compilation terminated.
compilation terminated.
CMakeFiles\Project.dir\build.make:61: recipe for target 'CMakeFiles/Project.dir/main.cpp.obj' failed
CMakeFiles\Project.dir\build.make:85: recipe for target 'CMakeFiles/Project.dir/soundclass.cpp.obj' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Project.dir/all' failed
mingw32-make.exe[3]: *** [CMakeFiles/Project.dir/main.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
mingw32-make.exe[3]: *** [CMakeFiles/Project.dir/soundclass.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Project.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Project.dir/rule' failed
Makefile:117: recipe for target 'Project' failed
mingw32-make.exe[1]: *** [CMakeFiles/Project.dir/rule] Error 2
mingw32-make.exe: *** [Project] Error 2
${WinSDK} cannot be set correctly since you are using the same variable in the same way for both include and library.
Other tips:
CMAKE_CXX_STANDARD does nothing for the MSVC compiler
it is better to use target_include_directories() than include_directories() to keep target information cleaner
As part of a project I'm working on, I need to make use of the WebKitGTK+ library.
I downloaded the library (tarball) and compiled it as described here.
After the compilation was done:
The lib's headers are in /usr/local/include.
The lib's .so files are in /usr/local/lib.
In my C++ project I tried to add the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.7)
project(CVE_2016_4657)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(CVE_2016_4657 ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
include_directories(/usr/local/include/webkitgtk-4.0)
link_directories(/usr/local/lib/webkit2gtk-4.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
pkg_check_modules(SOUP REQUIRED libsoup-2.4)
include_directories(${SOUP_INCLUDE_DIRS})
link_directories(${SOUP_LIBRARY_DIRS})
add_definitions(${SOUP_CFLAGS_OTHER})
target_link_libraries(
CVE_2016_4657
${GTK3_LIBRARIES}
${SOUP_LIBRARIES})
However, when compiling the project I'm getting the following error:
[ 50%] Linking CXX executable CVE_2016_4657
CMakeFiles/CVE_2016_4657.dir/main.cpp.o: In function `main':
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_get_type'
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_new'
/home/idanas/CLionProjects/Switcheroo/main.cpp:29: undefined reference to
`webkit_web_view_load_uri'
collect2: error: ld returned 1 exit status
CMakeFiles/CVE_2016_4657.dir/build.make:94: recipe for target
'CVE_2016_4657' failed
make[3]: *** [CVE_2016_4657] Error 1
CMakeFiles/Makefile2:67: recipe for target
'CMakeFiles/CVE_2016_4657.dir/all' failed
make[2]: *** [CMakeFiles/CVE_2016_4657.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target
'CMakeFiles/CVE_2016_4657.dir/rule' failed
make[1]: *** [CMakeFiles/CVE_2016_4657.dir/rule] Error 2
Makefile:118: recipe for target 'CVE_2016_4657' failed
make: *** [CVE_2016_4657] Error 2
I have little-to-none experience with CMake and could really use some help.
You are trying to use WebKitGTK+, which is a separate library from both GTK+ and libsoup. You will need to duplicate your pkg_check_modules() code again for WebKitGTK+. You'll need to determine first if you are using WebKit1 or WebKit2 (they have subtly different APIs), and then find the appropriate pkg-config name for that version of WebKitGTK+; check the documentation and the contents of your /usr/lib/pkgconfig directory.
I'm trying to link a downloaded library called ArduinoJson to my project with CMake, but it seems that whenever i include the file it is missing, it will just ask for the next file its missing. I will end up with a lot of include lines which i think isnt the right way. I cant seem to find the correct syntax to include a libary in CMake
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_FLAGS "-DTESTING")
include_directories(
/usr/share/arduino/libraries/ArduinoJson/include
/usr/share/arduino/hardware/arduino/cores/arduino
)
set(files
DataHandler.h
DataHandler.cpp
JSON.cpp
JSON.h
HAL_mock.cpp
HAL_mock.h
HAL_Protocol.h
lib/ArduinoJson/ArduinoJson.h
)
# Locate GTest
find_package(GTest REQUIRED)
# Link runTests with what we want to test and the GTest library
add_executable(runTests DataHandlerTests.cpp JSONTests.cpp HALTests.cpp ${files})
target_link_libraries(runTests GTest::Main ArduinoJson)
The error I get
[ 14%] Building CXX object CMakeFiles/runTests.dir/JSONTests.cpp.o
In file included from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/../String.hpp:14:0,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/DynamicStringBuilder.hpp:11,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:12,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonVariant.hpp:13,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonBuffer.hpp:14,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/BlockJsonBuffer.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.h:8,
from /usr/share/arduino/libraries/ArduinoJson/ArduinoJson.h:8,
from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSON.h:6,
from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSONTests.cpp:5:
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:29:26: fatal error: avr/pgmspace.h: No such file or directory
compilation terminated.
CMakeFiles/runTests.dir/build.make:86: recipe for target 'CMakeFiles/runTests.dir/JSONTests.cpp.o' failed
make[2]: *** [CMakeFiles/runTests.dir/JSONTests.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I would like to add 2 maybe 3 lines which include all the libraries i need for my ArduinoJson library