Locally it builds the project with grpc. but on gitlab it gives an error. Does anyone have any ideas? Locally, everything builds and works well. I get the problem when I use CI on gitlab. What could this error mean? I don't understand what exactly is required? I've also tried running with different compilers - the error persists.
$ cmake --build .
[ 4%] Running C++ gRPC compiler on include/protocol/proto/service.proto
[ 8%] Running cpp protocol buffer compiler on /builds/k-morozov/appchat/build/src/protocol
Could not map to virtual file: /builds/k-morozov/appchat/build/src/protocol: Input file is a directory.
make[2]: *** [src/protocol/CMakeFiles/protocol_lib.dir/build.make:63: src/protocol/protocol.pb.h] Error 1
make[1]: *** [CMakeFiles/Makefile2:93: src/protocol/CMakeFiles/protocol_lib.dir/all] Error 2
cmake:
cmake_minimum_required(VERSION 3.5)
set(PROTOBUF_FILES
"include/protocol/proto/messages.proto"
)
set(PROTOS_FILES
${PROTOBUF_FILES}
"include/protocol/proto/service.proto"
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Protobuf REQUIRED)
find_package(GRPC REQUIRED)
find_package(Threads REQUIRED)
set(PROTO_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR})
file(MAKE_DIRECTORY ${PROTO_SRC_DIR})
include_directories(${PROTO_SRC_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_SRC_DIR} ${PROTOS_FILES})
grpc_generate_cpp(GRPC_SRCS GRPC_HDRS ${PROTO_SRC_DIR} ${PROTOS_FILES})
set(PROTOCOL_LIB_NAME protocol_lib)
add_library(${PROTOCOL_LIB_NAME} STATIC)
target_sources(${PROTOCOL_LIB_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/protocol/protocol.h
PRIVATE
${PROTO_HDRS}
${PROTO_SRCS}
${GRPC_SRCS}
"include/protocol/command_table.h"
)
set_target_properties(${PROTOCOL_LIB_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
target_compile_options(${PROTOCOL_LIB_NAME} PRIVATE "-fPIC")
target_link_libraries(${PROTOCOL_LIB_NAME}
PUBLIC
gpr
gRPC::grpc++
protobuf::libprotobuf
gRPC::grpc++_reflection
PRIVATE
pthread
project_sanitizers
)
include_directories(${Protobuf_INCLUDE_DIRS})
target_include_directories(${PROTOCOL_LIB_NAME}
PUBLIC
"./include"
${CMAKE_BINARY_DIR}/src/protocol/
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
Related
I'm trying to compile QT5 in C++ with Cmake on mac M1,
For now i can try with Fedora and it's working, but not on my mac.
This is my CMake File :
cmake_minimum_required(VERSION 3.0)
project(rtype)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CPACK_OUTPUT_FILE_PREFIX "pack")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} src/ecs/main.cpp)
# Adding QT5 dependencies
find_package(Qt5 COMPONENTS Core Network REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
# Adding SFML dependencies
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics)
# Ajouter les includes pour SFML
target_include_directories(${PROJECT_NAME}
PRIVATE
${SFML_INCLUDE_DIRS})
# Setting up the CPack generator
set(CPACK_GENERATOR ZIP) # for macOS and Linux
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.icns)
set(CPACK_GENERATOR NSIS) # for Windows
set(CPACK_PACKAGE_NAME "RType")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
include(CPack)
# Setting up the install targets
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin)
install(FILES README.md
DESTINATION .)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/build.sh
DESTINATION .)
If I transform this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
to this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core)
or this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Network)
It's working perfectly, but with both its make this error :
[ 20%] Automatic MOC for target rtype
[ 20%] Built target rtype_autogen
[ 40%] Linking CXX executable /Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype
duplicate symbol 'qt_apple_sharedApplication()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_check_os_version()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_isApplicationExtension()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
[...]
duplicate symbol 'RunLoopDebugger::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
ld: 94 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype] Error 1
make[1]: *** [CMakeFiles/rtype.dir/all] Error 2
make: *** [all] Error 2
I don't understand why, is not compatible with M1 Chipset ?
Thank you,
Ilan
I'm on macOS 12.4 I have run xcode-select --install to install the build tools. I'm using VSCode and my c++ configurations I've added the mac frameworks as.
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks and /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/ The reason I added this second one is it contains a string.h file which contains a declaration for memset_s
The error generated is this:
/Users/Greeley/Workspace/Cppspace/Culinoire/build/subprojects/Source/wxWidgets_external/src/unix/utilsunx.cpp:229:5: error: use of undeclared identifier 'memset_s'
memset_s(v, n, 0, n);
^
1 error generated.
make[5]: *** [libs/base/CMakeFiles/wxbase.dir/__/__/__/__/src/unix/utilsunx.cpp.o] Error 1
make[4]: *** [libs/base/CMakeFiles/wxbase.dir/all] Error 2
make[3]: *** [all] Error 2
My code is here: https://github.com/Greeley/Culinoire but it's just CMakeLists.txt files right now, and the wxWidgets Hello World as main.cpp also my .vscode directory.
I followed this: this video https://www.youtube.com/watch?v=zdHqoyG73Jk
and this one https://www.youtube.com/watch?v=MfuBS9n5_aY
And then found this on github with the same issue.
https://github.com/wxWidgets/wxWidgets/issues/19334
and put the define at the top of main.cpp and put it in the defines array within c_cpp_properties.json however I still get the same error as above.
I really don't understand what's going wrong. I'd greatly appreciate some help.
there's 4 CMakeLists.txt in the project, these are their contents:
/CMakeLists.txt
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c")
set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++")
project(Culinoire LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ExternalProject base
set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subprojects)
set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage)
add_subdirectory(external)
include(ExternalProject)
ExternalProject_Add(${PROJECT_NAME}_core
DEPENDS
wxWidgets_external
SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/src
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}
-DwxWidgets_ROOT_DIR=${wxWidgets_ROOT_DIR}
-DENV_WX_CONFIG=${ENV_WX_CONFIG}
CMAKE_CACHE_ARGS
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS
1
INSTALL_COMMAND
""
)
Edit below: Changed static to 1 and universal to 0
/src/CMakeLists.txt
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c")
set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++")
project(wx_cmake_template_core LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(__STDC_WANT_LIB_EXT1__)
# hack for buggy CMake's FindwxWidgets script
if (DEFINED ENV_WX_CONFIG)
set (ENV{WX_CONFIG} ${ENV_WX_CONFIG})
endif()
set(wxWidgets_USE_DEBUG 1)
set(wxWidgets_USE_UNICODE 1)
set(wxWidgets_USE_UNIVERSAL 0)
set(wxWidgets_USE_STATIC 1)
set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
set(wxWidgets_ROOT_DIR "/Users/Greeley/Library/wxWidgets")
set(wxWidgets_LIBRARIES "/Users/Greeley/Library/wxWidgets/lib")
find_package(wxWidgets COMPONENTS core base REQUIRED HINT ${wxWidgets_ROOT_DIR})
set(SRCS main.cpp)
if (APPLE)
# create bundle on apple compiles
add_executable(main MACOSX_BUNDLE ${SRCS} )
# Set a custom plist file for the app bundle - needed for Mac OS Retina display
set_target_properties(main PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
else()
# the WIN32 is needed for Windows in order for it to look for WinMain
# instead of the main function. This is ignored on other systems,
# so it works on all platforms
add_executable(main WIN32 ${SRCS})
endif()
target_link_libraries(main PRIVATE ${wxWidgets_LIBRARIES})
/external/CMAkeLists.txt
add_subdirectory(wxwidgets)
/external/wxwidgets/CMakeLists.txt
# check if wxWidgets is already installed in the system - using CMake's built in script FindwxWidgets
find_package(wxWidgets QUIET)
if (wxWidgets_FOUND)
message(STATUS "Found preinstalled wxWidgets libraries at ${wxWidgets_LIBRARIES}")
add_library(wxWidgets_external INTERFACE)
else()
message(STATUS "Preinstalled wxWidgets not found.")
message(STATUS "Will download and install wxWidgets in ${STAGED_INSTALL_PREFIX}")
include(ExternalProject)
ExternalProject_Add(wxWidgets_external
GIT_REPOSITORY
https://github.com/wxWidgets/wxWidgets.git
GIT_TAG
3.2
UPDATE_COMMAND
""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}
-DwxBUILD_SHARED=OFF
CMAKE_CACHE_ARGS
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
TEST_AFTER_INSTALL
0
DOWNLOAD_NO_PROGRESS
1
LOG_CONFIGURE
1
LOG_BUILD
1
LOG_INSTALL
1
)
set(wxWidgets_ROOT_DIR ${STAGED_INSTALL_PREFIX})
file(TO_NATIVE_PATH "${wxWidgets_ROOT_DIR}" wxWidgets_ROOT_DIR)
set(wxWidgets_ROOT_DIR ${wxWidgets_ROOT_DIR} CACHE INTERNAL "wxWidgets installation dir")
set (ENV_WX_CONFIG ${STAGED_INSTALL_PREFIX}/bin/wx-config)
file (TO_NATIVE_PATH "${ENV_WX_CONFIG}" ENV_WX_CONFIG)
set(ENV_WX_CONFIG ${ENV_WX_CONFIG} CACHE INTERNAL "wx-config dir")
endif()
EDIT BELOW
I changed the CMakeLists.txt file to
# check if wxWidgets is already installed in the system - using CMake's built in script FindwxWidgets
find_package(wxWidgets QUIET)
if (wxWidgets_FOUND)
message(STATUS "Found preinstalled wxWidgets libraries at ${wxWidgets_LIBRARIES}")
add_library(wxWidgets INTERFACE)
else()
message(STATUS "Preinstalled wxWidgets not found.")
message(STATUS "Will download and install wxWidgets in ${STAGED_INSTALL_PREFIX}")
include(ExternalProject)
ExternalProject_Add(wxWidgets
GIT_REPOSITORY
https://github.com/wxWidgets/wxWidgets.git
GIT_TAG
master
UPDATE_COMMAND
""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DwxBUILD_SHARED=OFF
CMAKE_CACHE_ARGS
TEST_AFTER_INSTALL
0
DOWNLOAD_NO_PROGRESS
1
LOG_CONFIGURE
1
LOG_BUILD
1
LOG_INSTALL
1
)
set(wxWidgets_ROOT_DIR ${STAGED_INSTALL_PREFIX})
file(TO_NATIVE_PATH "${wxWidgets_ROOT_DIR}" wxWidgets_ROOT_DIR)
set(wxWidgets_ROOT_DIR ${wxWidgets_ROOT_DIR} CACHE INTERNAL "wxWidgets installation dir")
set (ENV_WX_CONFIG ${STAGED_INSTALL_PREFIX}/bin/wx-config)
file (TO_NATIVE_PATH "${ENV_WX_CONFIG}" ENV_WX_CONFIG)
set(ENV_WX_CONFIG ${ENV_WX_CONFIG} CACHE INTERNAL "wx-config dir")
endif()
The build now completes and wxWidgets is 'found' but then goes to fail because wx/wx.h isn't found
-- Found wxWidgets: -L/Users/Greeley/Workspace/Cppspace/Culinoire/build/stage/lib;-pthread;/Users/Greeley/Workspace/Cppspace/Culinoire/build/stage/lib/libwx_osx_cocoau_core-3.2.a;/Users/Greeley/Workspace/Cppspace/Culinoire/build/stage/lib/libwx_baseu-3.2.a;-lwx_baseu-3.2;-lwxjpeg-3.2;-lwxpng-3.2;-lwxtiff-3.2;-framework AudioToolbox;-framework WebKit;/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/lib/libz.tbd;-lwxregexu-3.2;/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/lib/libiconv.tbd;-framework CoreFoundation;-framework Security;-framework Carbon;-framework Cocoa;-framework IOKit;-framework QuartzCore (found version "3.2.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Greeley/Workspace/Cppspace/Culinoire/build/subprojects/Build/Culinoire_core
[ 87%] Performing build step for 'Culinoire_core'
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/Users/Greeley/Workspace/Cppspace/Culinoire/src/main.cpp:3:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
^~~~~~~~~~~~~
1 error generated.
make[5]: *** [CMakeFiles/main.dir/main.cpp.o] Error 1
make[4]: *** [CMakeFiles/main.dir/all] Error 2
make[3]: *** [all] Error 2
make[2]: *** [subprojects/Stamp/Culinoire_core/Culinoire_core-build] Error 2
make[1]: *** [CMakeFiles/Culinoire_core.dir/all] Error 2
make: *** [all] Error 2
in /src/CMakeLists.txt I added
include(${wxWidgets_USE_FILE})
and changed the project name to reflect my actual project name.
so the entire file looks like this
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c")
set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++")
project(Culinoire LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(__STDC_WANT_LIB_EXT1__)
# hack for buggy CMake's FindwxWidgets script
if (DEFINED ENV_WX_CONFIG)
set (ENV{WX_CONFIG} ${ENV_WX_CONFIG})
endif()
set(wxWidgets_USE_DEBUG 1)
set(wxWidgets_USE_UNICODE 1)
set(wxWidgets_USE_UNIVERSAL 0)
set(wxWidgets_USE_STATIC 1)
#set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
find_package(wxWidgets COMPONENTS core base REQUIRED)
set(SRCS main.cpp)
include(${wxWidgets_USE_FILE})
if (APPLE)
# create bundle on apple compiles
add_executable(main MACOSX_BUNDLE ${SRCS} )
# Set a custom plist file for the app bundle - needed for Mac OS Retina display
set_target_properties(main PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
else()
# the WIN32 is needed for Windows in order for it to look for WinMain
# instead of the main function. This is ignored on other systems,
# so it works on all platforms
add_executable(main WIN32 ${SRCS})
endif()
target_link_libraries(main PRIVATE ${wxWidgets_LIBRARIES})
and my output now is
[main] Building folder: Culinoire
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /Users/Greeley/Workspace/Cppspace/Culinoire/build --config Debug --target all -j 10 --
[build] [ 50%] Built target wxWidgets
[build] [ 56%] Performing build step for 'Culinoire_core'
[main] Changes were detected in CMakeLists.txt but we could not reconfigure the project because another operation is already in progress.
[build] -- Configuring done
[build] -- Generating done
[build] -- Build files have been written to: /Users/Greeley/Workspace/Cppspace/Culinoire/build/subprojects/Build/Culinoire_core
[build] [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[build] [100%] Linking CXX executable main.app/Contents/MacOS/main
[build] [100%] Built target main
[build] [ 62%] No install step for 'Culinoire_core'
[build] [ 68%] Completed 'Culinoire_core'
[build] [100%] Built target Culinoire_core
[build] Build finished with exit code 0
[cpptools] The build configurations generated do not contain the active build configuration. Using "" for CMAKE_BUILD_TYPE instead of "Debug" to ensure that IntelliSense configurations can be found
I was trying to build GTest from source and then link my target to it using cmake. But I see this error
mygtest % cmake --build build
[ 50%] Building CXX object CMakeFiles/hello_test.dir/mytest.cpp.o
/path/to/test/mygtest/mytest.cpp:1:10: fatal error: 'gtest/gtest.h' file not found
#include <gtest/gtest.h>
^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/hello_test.dir/mytest.cpp.o] Error 1
make[1]: *** [CMakeFiles/hello_test.dir/all] Error 2
make: *** [all] Error 2
My question is what may I miss here?
This is my CMakeList File
cmake_minimum_required(VERSION 3.14)
project(my_project)
set(CMAKE_CXX_STANDARD 14)
find_library(
GTEST_MAIN
gtest_main
PATHS /path/to/googletest/build/lib/
NO_DEFAULT_PATH
)
enable_testing()
add_executable(
hello_test
mytest.cpp
)
target_link_libraries(
hello_test
${GTEST_MAIN}
)
include(GoogleTest)
gtest_discover_tests(hello_test)
What did I try?
Printing the target's link libraries
get_target_property(HELLO_TEST_LIBRARIES hello_test LINK_LIBRARIES)
include(CMakePrintHelpers)
cmake_print_variables(HELLO_TEST_LIBRARIES)
// OUTPUT
-- HELLO_TEST_LIBRARIES="/path/to/googletest/build/lib/libgtest_main.a"
using find_package(GTest) and then linking GTest::gtest works, but I don't want to use a precompiled version -- it seems to cause the error "Unfound Symbol" as mentioned here
I am open to any other better answers, but would post my current solution for those who might be interested.
Thanks #Alex Reinking and #SpacePotatoes for comments. based on what's suggested, inserting the following piece of codes to your CMakeLists.txt would allow you to automate the process of downloading googletest and building from source.
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
SUBBUILD_DIR ${PROJECT_BINARY_DIR}/googletest-subbuild
BINARY_DIR ${PROJECT_BINARY_DIR}/googletest-build
SOURCE_DIR ${PROJECT_BINARY_DIR}/googletest-src
)
FetchContent_Populate(
googletest
)
execute_process(COMMAND cmake -S. -B${googletest_BINARY_DIR} WORKING_DIRECTORY ${googletest_SOURCE_DIR})
execute_process(COMMAND cmake --build . WORKING_DIRECTORY ${googletest_BINARY_DIR})
set(GTEST_LIBRARY ${googletest_BINARY_DIR}/lib/libgtest.a)
set(GTEST_INCLUDE_DIR ${googletest_SOURCE_DIR}/googletest/include)
set(GTEST_MAIN_LIBRARY ${googletest_BINARY_DIR}/lib/libgtest_main.a)
find_package(GTest REQUIRED)
Then you might be able to link to your target with
target_link_libraries(<target> GTest::gtest_main)
Hello I was working on a C++ project, and had a cmake file that was working just fine, until I tried to add cuda into the C++ project. I am building this project on the NVIDIA Jetson Nano.
I get this error while building:
nvlink fatal : Could not open input file 'CMakeFiles/MY_APP.dir/src/MY_APP.cpp.o' (target: sm_35)
The rest of the error underneath that looks like this:
CMakeFiles/MY_APP.dir/build.make:552: recipe for target
'CMakeFiles/MY_APP.dir/cmake_device_link.o' failed
make[2]: *** [CMakeFiles/MY_APP.dir/cmake_device_link.o] Error 1
make[2]: Leaving directory '/home/me/Code/MyApp/build'
CMakeFiles/Makefile2:127: recipe for target 'CMakeFiles/MY_APP.dir/all' failed
make[1]: *** [CMakeFiles/MY_APP.dir/all] Error 2
make[1]: Leaving directory '/home/me/Code/MY_APP/build'
Makefile:155: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/home/me/Code/MY_APP/build'
I run my cmake file using a script I called confgure.sh, which looks like this:
#!/bin/sh
cmake -S . -B build -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-10.2/bin/nvcc
I run my make file using a script I called build.sh, which looks like this:
#!/bin/sh
make -C build
My Cmake File looks like this:
cmake_minimum_required(VERSION 3.21.0)
project(MY_APP VERSION 0.0.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
enable_language(CUDA)
# Pass options to NVCC
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3 -gencode arch=compute_35,code=sm_35
)
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
FILE(GLOB_RECURSE MY_CUDA_SRCS src/*.cu)
configure_file(src/MyAppConfig.h.in MyAppConfig.h)
#collect cpp files
FILE(GLOB_RECURSE SRC src/*.cpp)
find_package(CUDA QUIET)
if(CUDA_FOUND)
SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
include_directories(${CUDA_INCLUDE_DIRS})
get_filename_component(CUDA_LIBRARY_DIR ${CUDA_CUDART_LIBRARY} DIRECTORY)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-L${CUDA_LIBRARY_DIR}")
SET(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})
#${CUDA_CUDART_LIBRARY}
#${CMAKE_CUDA_RUNTIME_LIBRARY}
#)
SET(LIBS ${LIBS} ${ALL_CUDA_LIBS})
message(STATUS "CUDA_LIBRARIES: ${CUDA_INCLUDE_DIRS} ${ALL_CUDA_LIBS}")
set(CUDA_PROPAGATE_HOST_FLAGS ON)
set(CUDA_SEPARABLE_COMPILATION ON)
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_35,code=sm_35)
#collect CUDA files
FILE(GLOB_RECURSE CUDA_SRC src/*.cu)
#build static library
#CUDA_ADD_LIBRARY(my_cuda_lib ${CUDA_SRC} STATIC)
cuda_compile(cuda_objs ${CUDA_SRC})
SET(SRC ${cuda_objs} ${SRC})
SET(LIBS ${LIBS} ${my_cuda_lib})
endif()
link_libraries(${cuda_objs})
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CUDA)
message("using cuda_add_executable")
cuda_add_executable(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} ${LIBS})
#DOWNLOAD ALL THE SUBMODULES
find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE, "Check submodules during build" ON)
if (GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE}
submodule update --init --recursvie
WORKING_DIRECTORY {CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE_GIT_SUBMOD_RESULT)
if (NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR
"git submodule update --init failed with ${GIT_SUMOD_RESULT},
please check submodule")
endif()
endif()
endif()
#CHECK ALL THE SUBMODULES
if (NOT EXISTS
"${PROJECT_SOURCE_DIR}/external/Simple-Websocket-Server/CMakeLists.txt")
message(FATAL_ERROR
"The Simple-Websocket-Server submodule was not downloaded!
GIT_SUBMODULE was turned off or failed. Please update submodule")
endif()
add_subdirectory(external/Simple-Websocket-Server)
include_directories(PUBLIC external/Simple-Websocket-Server)
find_package(PythonLibs REQUIRED)
find_package(pybind11 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}
curl pthread crypto boost_system jsoncpp ${PYTHON_LIBRARIES} cudart
#<some-of-my-other-libraries>
)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/MyAppConfig.h" DESTINATION include)
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${MY_APP_VERSION_PATCH}")
include(CPack)
set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
"${CMAKE_CUDA_COMPILER} ${_CMAKE_CUDA_EXTRA_FLAGS} -c ${MY_CUDA_SRCS}")
message(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION)
I am lost on how to get CUDA added to my project that already contains a bunch of C++ files, and I need to be able to call my .cu files from a .cpp file other then main.cpp, and I need to get this building in CMake, and I am doing it on the jetson nano. Any help on solving this error?
You are mixing up a lot of CUDA-related definitions and commands, including some from an earlier "era" of CUDA support in CMake.
Among other things:
Your CMakeLists.txt is overriding your environment setting for the CUDA compiler location.
... and actually, you shouldn't bother setting that location anyway, since you've already set the CUDA toolkit root.
Don't use find_package(CUDA) with CMake versions of 3.17 or 3.18, or later. For all relevant toolkit-related paths, use find_package(CUDAToolkit)`, which does... well, less but also more.
Don't use cuda_add_+suffix commands. Since CMake supports CUDA natively, you use regular add_executable, add_library etc.
There are further issues with your CMakeLists.txt file - not all of them CUDA-related, but that should be enough to get you started. It may not in itself resolve the specific bottom-line problem you have, though.
You may want to have a look at public repositories using CUDA and recent CMake versions to get an idea of how this is done.
I have a simple cmake project going that I can't get to compile on OS X 10.8.4. The cmake/make process works great on Linux but on OS X I am getting this error:
Linking CXX static library libImageFilter.a
ar: no archive members specified
...
make[2]: *** [lib/libImageFilter.a] Error 1
make[1]: *** [lib/CMakeFiles/ImageFilter.dir/all] Error 2
make: *** [all] Error 2
I am using the Eclipse CDT4 Generator Unix MakeFile on both platforms. This seems like something to with the difference between ar on the two systems. But, I couldn't find much on google to help me troubleshoot.
Here is some more info for you
src/CMakeList.txt
make_minimum_required(VERSION 2.8)
project(itkNormals)
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
add_subdirectory(test)
add_subdirectory(lib)
src/lib/CMakeList.txt
add_library(DotImageFilter itkDotImageFilter.h)
SET_TARGET_PROPERTIES(DotImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(DotImageFilter ${ITK_LIBRARIES})
add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})
src/test/CMakeLists.txt:
include_directories(${PROJECT_SOURCE_DIR}/lib)
add_executable(itkNormalsMain itkNormals.cxx)
TARGET_LINK_LIBRARIES(itkNormalsMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(itkNormalsMain ImageFilter)
TARGET_LINK_LIBRARIES(itkNormalsMain DotImageFilter)
add_executable(dotTestMain dotTester.cxx)
TARGET_LINK_LIBRARIES(dotTestMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(dotTestMain ImageFilter)
TARGET_LINK_LIBRARIES(dotTestMain DotImageFilter)
add_executable(IST ImageSourceTest.cxx)
TARGET_LINK_LIBRARIES(IST ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(IST ImageFilter)
You can't create library from one header file:
add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})
that's the reason why you set LINKER_LANGUAGE explicitly - there is nothing to link and cmake is confused.
So include_directories is enough:
include_directories(${PROJECT_SOURCE_DIR}/lib)
BTW:
You don't need to check ITK_FOUND if you specify REQUIRED:
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
from documentation:
The REQUIRED option stops processing with an error message if the package cannot be found.
PROJECT_SOURCE_DIR is not necessary equal itkNormals_SOURCE_DIR (you may use this file from other project):
include_directories(${PROJECT_SOURCE_DIR}/lib)
Can be fixed one of this way:
include_directories(${itkNormals_SOURCE_DIR}/lib)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../lib)
or simply include from parent file:
# src/CMakeLists.txt
include_directories("./lib")