CMake and vcpkg linker error and crazy naming - cmake

I am using vcpkg for the first time with amqpcpp. I am testing it out with cmake to get a project setup using a library. vcpkg installs the package correctly and cmake has no trouble finding the target amqpcpp. There is some issue with the linker that I cannot solve. Below is my CMakeLists.txt.
cmake_minimum_required(VERSION 3.15)
set(VCPKG_TARGET_TRIPLET x86-windows )
set(CMAKE_TOOLCHAIN_FILE "C:/Users/reine/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
project(amqp_test)
set(CMAKE_CXX_STANDARD 11)
find_package(amqpcpp CONFIG REQUIRED)
include_directories(${amqpcpp_INCLUDE_DIR})
add_executable(amqp_test main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE amqpcpp)
And below is the linker error that I am experiencing. The ConnectionImpl does indeed exist. Why are the file names so crazy? I imagine this is something that is done to prevent double referencing of an object. I am thinking this is where my problem is.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\amqp_test.dir/objects.a(main.cpp.obj): in function `ZN4AMQP10ConnectionD1Ev':
C:/Users/reine/vcpkg/installed/x86-windows/include/amqpcpp/connection.h:70: undefined reference to `AMQP::ConnectionImpl::~ConnectionImpl()'
I have done my due diligence searching this type of linker error and am completely stuck.
Verbose Make Output
Clean finished
====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug --target all -- -j 4
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -SC:\Users\reine\CLionProjects\amqp-test -BC:\Users\reine\CLionProjects\amqp-test\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E cmake_progress_start C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug\CMakeFiles C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug\CMakeFiles\progress.marks
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\amqp_test.dir\build.make CMakeFiles/amqp_test.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\reine\CLionProjects\amqp-test C:\Users\reine\CLionProjects\amqp-test C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug C:\Users\reine\CLionProjects\amqp-test\cmake-build-debug\CMakeFiles\amqp_test.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\amqp_test.dir\build.make CMakeFiles/amqp_test.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
[ 50%] Building CXX object CMakeFiles/amqp_test.dir/main.cpp.obj
C:\MinGW\bin\g++.exe #CMakeFiles/amqp_test.dir/includes_CXX.rsp -g -std=gnu++11 -o CMakeFiles\amqp_test.dir\main.cpp.obj -c C:\Users\reine\CLionProjects\amqp-test\main.cpp
[100%] Linking CXX executable amqp_test.exe
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\amqp_test.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E remove -f CMakeFiles\amqp_test.dir/objects.a
C:\MinGW\bin\ar.exe cr CMakeFiles\amqp_test.dir/objects.a #CMakeFiles\amqp_test.dir\objects1.rsp
C:\MinGW\bin\g++.exe -g -Wl,--whole-archive CMakeFiles\amqp_test.dir/objects.a -Wl,--no-whole-archive -o amqp_test.exe -Wl,--out-implib,libamqp_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\amqp_test.dir\linklibs.rsp
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\amqp_test.dir/objects.a(main.cpp.obj): in function `ZN4AMQP10ConnectionC1EPNS_17ConnectionHandlerERKNS_5LoginERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE':
C:/Users/reine/vcpkg/installed/x86-windows/include/amqpcpp/connection.h:40: undefined reference to `AMQP::ConnectionImpl::ConnectionImpl(AMQP::Connection*, AMQP::ConnectionHandler*, AMQP::Login const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\amqp_test.dir/objects.a(main.cpp.obj): in function `ZN4AMQP10ConnectionD1Ev':
C:/Users/reine/vcpkg/installed/x86-windows/include/amqpcpp/connection.h:70: undefined reference to `AMQP::ConnectionImpl::~ConnectionImpl()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\amqp_test.dir\build.make:89: recipe for target 'amqp_test.exe' failed
mingw32-make.exe[2]: Leaving directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
mingw32-make.exe[2]: *** [amqp_test.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/amqp_test.dir/all] Error 2
CMakeFiles\Makefile2:77: recipe for target 'CMakeFiles/amqp_test.dir/all' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/reine/CLionProjects/amqp-test/cmake-build-debug'
Makefile:85: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

Related

CMake failed to link static CUDA library

I create a static library following an Nvidia example
Here is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "")
set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc" CACHE FILEPATH "")
set(CMAKE_CUDA_HOST_COMPILER "/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc" CACHE FILEPATH "")
project(cmake_and_cuda LANGUAGES CUDA CXX)
add_library(particles STATIC
randomize.cpp
randomize.h
particle.cu
particle.h
v3.cu
v3.h
calc.h
calc.cu
)
target_link_libraries(particles PRIVATE stdc++)
set_target_properties(particles PROPERTIES LANGUAGE CUDA)
set_target_properties(particles PROPERTIES LINKER_LANGUAGE CUDA)
target_compile_options(particles PRIVATE $<$<COMPILE_LANGUAGE:CUDA>: "--std=c++11" >)
set_target_properties(particles PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
# build executable
add_executable(particle_test main.cpp)
set_target_properties(particle_test PROPERTIES LANGUAGE CXX)
set_target_properties(particle_test PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(particle_test PRIVATE particles)
The build is successful. Here is the build log:
jenkins#ubuntu:~/git_repos/test/test_gpu/build$ make
/usr/bin/cmake -H/home/jenkins/git_repos/test/test_gpu -B/home/jenkins/git_repos/test/test_gpu/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
make -f CMakeFiles/particles.dir/build.make CMakeFiles/particles.dir/depend
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
cd /home/jenkins/git_repos/test/test_gpu/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles/particles.dir/DependInfo.cmake --color=
Scanning dependencies of target particles
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
make -f CMakeFiles/particles.dir/build.make CMakeFiles/particles.dir/build
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
[ 12%] Building CXX object CMakeFiles/particles.dir/randomize.cpp.o
/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/ntoaarch64-g++ -o CMakeFiles/particles.dir/randomize.cpp.o -c /home/jenkins/git_repos/test/test_gpu/randomize.cpp
[ 25%] Building CUDA object CMakeFiles/particles.dir/particle.cu.o
/usr/local/cuda/bin/nvcc -ccbin=/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc --std=c++11 -x cu -dc /home/jenkins/git_repos/test/test_gpu/particle.cu -o CMakeFiles/particles.dir/particle.cu.o
[ 37%] Building CUDA object CMakeFiles/particles.dir/v3.cu.o
/usr/local/cuda/bin/nvcc -ccbin=/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc --std=c++11 -x cu -dc /home/jenkins/git_repos/test/test_gpu/v3.cu -o CMakeFiles/particles.dir/v3.cu.o
[ 50%] Building CUDA object CMakeFiles/particles.dir/calc.cu.o
/usr/local/cuda/bin/nvcc -ccbin=/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc --std=c++11 -x cu -dc /home/jenkins/git_repos/test/test_gpu/calc.cu -o CMakeFiles/particles.dir/calc.cu.o
[ 62%] Linking CUDA static library libparticles.a
/usr/bin/cmake -P CMakeFiles/particles.dir/cmake_clean_target.cmake
/usr/bin/cmake -E cmake_link_script CMakeFiles/particles.dir/link.txt --verbose=1
/usr/bin/ar qc libparticles.a CMakeFiles/particles.dir/randomize.cpp.o CMakeFiles/particles.dir/particle.cu.o CMakeFiles/particles.dir/v3.cu.o CMakeFiles/particles.dir/calc.cu.o
/usr/bin/ranlib libparticles.a
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
[ 62%] Built target particles
make -f CMakeFiles/particle_test.dir/build.make CMakeFiles/particle_test.dir/depend
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
cd /home/jenkins/git_repos/test/test_gpu/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles/particle_test.dir/DependInfo.cmake --color=
Scanning dependencies of target particle_test
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
make -f CMakeFiles/particle_test.dir/build.make CMakeFiles/particle_test.dir/build
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
[ 75%] Building CXX object CMakeFiles/particle_test.dir/main.cpp.o
/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/ntoaarch64-g++ -o CMakeFiles/particle_test.dir/main.cpp.o -c /home/jenkins/git_repos/test/test_gpu/main.cpp
[ 87%] Linking CUDA device code CMakeFiles/particle_test.dir/cmake_device_link.o
/usr/bin/cmake -E cmake_link_script CMakeFiles/particle_test.dir/dlink.txt --verbose=1
/usr/local/cuda/bin/nvcc -ccbin=/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc -Xcompiler=-fPIC -Wno-deprecated-gpu-targets -shared -dlink CMakeFiles/particle_test.dir/main.cpp.o -o CMakeFiles/particle_test.dir/cmake_device_link.o -L/usr/local/cuda/targets/aarch64-qnx/lib/stubs -L/usr/local/cuda/targets/aarch64-qnx/lib libparticles.a
[100%] Linking CXX executable particle_test
/usr/bin/cmake -E cmake_link_script CMakeFiles/particle_test.dir/link.txt --verbose=1
/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/ntoaarch64-g++ CMakeFiles/particle_test.dir/main.cpp.o CMakeFiles/particle_test.dir/cmake_device_link.o -o particle_test -L/usr/local/cuda/targets/aarch64-qnx/lib/stubs -L/usr/local/cuda/targets/aarch64-qnx/lib libparticles.a -lstdc++ -lcudadevrt -lcudart_static
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
[100%] Built target particle_test
However, if I want to export libparticles.a and uses it in another project, it does not work.
target_link_libraries(another_project PRIVATE ${CMAKE_SOURCE_DIR}/libparticles.a)
The error log:
jenkins#ubuntu:~/git_repos/test/test_gpu/build$ make
/usr/bin/cmake -H/home/jenkins/git_repos/test/test_gpu -B/home/jenkins/git_repos/test/test_gpu/build --check-build-system CMakeFiles/Makefile.cmake 0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jenkins/git_repos/test/test_gpu/build
/usr/bin/cmake -E cmake_progress_start /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
make -f CMakeFiles/another_project.dir/build.make CMakeFiles/another_project.dir/depend
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
cd /home/jenkins/git_repos/test/test_gpu/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build /home/jenkins/git_repos/test/test_gpu/build/CMakeFiles/another_project.dir/DependInfo.cmake --color=
Scanning dependencies of target another_project
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
make -f CMakeFiles/particle_test.dir/build.make CMakeFiles/another_project.dir/build
make[2]: Entering directory '/home/jenkins/git_repos/test/test_gpu/build'
[ 50%] Linking CXX executable particle_test
/usr/bin/cmake -E cmake_link_script CMakeFiles/another_project.dir/link.txt --verbose=1
/opt/qos2.1.1-build4288/host/linux/x86_64/usr/bin/ntoaarch64-g++ CMakeFiles/another_project.dir/main.cpp.o -o another_project ../libparticles.a
../libparticles.a(calc.cu.o): In function `calc::calc_func()':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x58): undefined reference to `cudaGetLastError'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x70): undefined reference to `cudaGetErrorString'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x104): undefined reference to `cudaDeviceSynchronize'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x108): undefined reference to `cudaGetLastError'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x120): undefined reference to `cudaGetErrorString'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x15c): undefined reference to `cudaMemcpy'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x160): undefined reference to `cudaDeviceSynchronize'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x164): undefined reference to `cudaGetLastError'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x17c): undefined reference to `cudaGetErrorString'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x210): undefined reference to `__cudaPushCallConfiguration'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x22c): undefined reference to `cudaGetLastError'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x244): undefined reference to `cudaGetErrorString'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x25c): undefined reference to `cudaDeviceSynchronize'
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x294): undefined reference to `cudaMemcpy'
../libparticles.a(calc.cu.o): In function `__cudaUnregisterBinaryUtil()':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x480): undefined reference to `__cudaUnregisterFatBinary'
../libparticles.a(calc.cu.o): In function `__nv_init_managed_rt_with_module(void**)':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x4a0): undefined reference to `__cudaInitModule'
../libparticles.a(calc.cu.o): In function `__device_stub__Z16advanceParticlesfP8particlei(float, particle*, int)':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x5bc): undefined reference to `__cudaPopCallConfiguration'
../libparticles.a(calc.cu.o): In function `__nv_cudaEntityRegisterCallback(void**)':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x708): undefined reference to `__cudaRegisterFunction'
../libparticles.a(calc.cu.o): In function `__sti____cudaRegisterAll()':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x744): undefined reference to `__cudaRegisterLinkedBinary_39_tmpxft_00036041_00000000_6_calc_cpp1_ii_78a77cc9'
../libparticles.a(calc.cu.o): In function `cudaError cudaMalloc<particle>(particle**, unsigned long)':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x76c): undefined reference to `cudaMalloc'
../libparticles.a(calc.cu.o): In function `cudaError cudaLaunchKernel<char>(char const*, dim3, dim3, void**, unsigned long, CUstream_st*)':
tmpxft_00036041_00000000-5_calc.cudafe1.cpp:(.text+0x7e8): undefined reference to `cudaLaunchKernel'
../libparticles.a(particle.cu.o): In function `__cudaUnregisterBinaryUtil()':
tmpxft_00035ff9_00000000-5_particle.cudafe1.cpp:(.text+0x1c4): undefined reference to `__cudaUnregisterFatBinary'
../libparticles.a(particle.cu.o): In function `__nv_init_managed_rt_with_module(void**)':
tmpxft_00035ff9_00000000-5_particle.cudafe1.cpp:(.text+0x1e4): undefined reference to `__cudaInitModule'
../libparticles.a(particle.cu.o): In function `__sti____cudaRegisterAll()':
tmpxft_00035ff9_00000000-5_particle.cudafe1.cpp:(.text+0x24c): undefined reference to `__cudaRegisterLinkedBinary_43_tmpxft_00035ff9_00000000_6_particle_cpp1_ii_bd5b23a5'
../libparticles.a(v3.cu.o): In function `__cudaUnregisterBinaryUtil()':
tmpxft_00036017_00000000-5_v3.cudafe1.cpp:(.text+0x3ac): undefined reference to `__cudaUnregisterFatBinary'
../libparticles.a(v3.cu.o): In function `__nv_init_managed_rt_with_module(void**)':
tmpxft_00036017_00000000-5_v3.cudafe1.cpp:(.text+0x3cc): undefined reference to `__cudaInitModule'
../libparticles.a(v3.cu.o): In function `__sti____cudaRegisterAll()':
tmpxft_00036017_00000000-5_v3.cudafe1.cpp:(.text+0x434): undefined reference to `__cudaRegisterLinkedBinary_37_tmpxft_00036017_00000000_6_v3_cpp1_ii_ec982148'
collect2: error: ld returned 1 exit status
CMakeFiles/particle_test.dir/build.make:98: recipe for target 'another_project' failed
make[2]: *** [particle_test] Error 1
make[2]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/another_project.dir/all' failed
make[1]: *** [CMakeFiles/another_project.dir/all] Error 2
make[1]: Leaving directory '/home/jenkins/git_repos/test/test_gpu/build'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2
I cannot understand the reason. In the end, I want to send libparticles.a to another developer and let him use it. Any help is really appreciated since I stuck at this problem for a while now.
Its about how GCC links library, if the name of lib is particles try this
target_link_directories(another_project PRIVATE /home/path_to_dir_containing_lib_a_file)
target_link_libraries(another_project PRIVATE particles)
Please see this manual:
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
The -l option is passed directly to the linker by GCC. Refer to your linker documentation for exact details. The general description below applies to the GNU linker.
The linker searches a standard list of directories for the library. The directories searched include several standard system directories plus any that you specify with -L.
It means that dirs containing libraries are passed separatly (under another flag) from library name

Unable to build FreeRTOS WIN32 demo in Clion

Below is the CmakeLists file that I'm using. I'm using the linker flags from eclipse as it seems to build in eclipse properly.
project(new1 LANGUAGES CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 14)
# Compiler options for compiling MinGW targets.
set(CMAKE_C_FLAGS_DEBUG "-D_WIN32_WINNT=0x0601 -DprojCOVERAGE_TEST=0 -fmessage-length=0 -Wcast-qual")
#-------------------------------------------------------------
# Linker options for Linking MinGW targets.
set(CMAKE_EXE_LINKER_FLAGS "-Xlinker -lwinmm")
#-------------------------------------------------------------
include_directories(FreeRTOS/Source/include
FreeRTOS/Source/portable/MSVC-MingW
/)
add_subdirectory(FreeRTOS/Source)
add_executable(application main.cpp)
target_link_libraries(application kernel)
target_link_libraries(application winmm.lib)
The below is the build output
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\application.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -E remove -f CMakeFiles\application.dir/objects.a
"F:\TrueSTUDIO for STM32 9.0.0\PCTools\bin\ar.exe" cr CMakeFiles\application.dir/objects.a #CMakeFiles\application.dir\objects1.rsp
"F:\TrueSTUDIO for STM32 9.0.0\PCTools\bin\g++.exe" -g -Xlinker -lwinmm -Wl,--whole-archive CMakeFiles\application.dir/objects.a -Wl,--no-whole-archive -o application.exe -Wl,--out-implib,libapplication.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\application.dir\linklibs.rsp
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0x15): undefined reference to `timeGetDevCaps#8'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0x2d): undefined reference to `timeBeginPeriod#4'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0xd5): undefined reference to `timeGetDevCaps#8'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0xe7): undefined reference to `timeEndPeriod#4'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [application.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/application.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/application.dir/rule] Error 2
mingw32-make.exe: *** [application] Error 2
Can somebody help please.
So, there was no issue with linking the winmm library it is just that I'm linking this to a wrong target. It was a dependency of the windows port in freeRTOS/Source/Portable.

Unable to use specific compiler in cmake created CodeBlocks project

I have various projects that I need to compile them with different compilers.
So, what I need is an IDE that lets easily allow me to choose/change a target and compile projects for that target.
Another need is to use cmake.
I am now trying CodeBlocks in windows. First I try to add a compiler:
I have set:
Settings->Toolchain executables->Compiler's installation directory->Program Files
Then I create CodeBlocks project with cmake -G "CodeBlocks - MinGW Makefiles"
I open the project in CodeBlocks that is generated by cmake.
I chose compiler in Project Settings.
I build.
Then I discover that compiler in Project Settings is totally ignored! Because it is used the one in CMakeCache.
Thus, I write a script that first set CC and CXX, then run cmake.
With this way I see that CMakeCache has the compiler that I want.
Then I build the project in CodeBlocks.
Now, for g++.exe, the correct compiler is used. However, CodeBlocks insists and insists again to use default MinGW compiler (which is in path) for mingw32-make.exe
Here is the last build output, where D:/Qt/Qt5.4.1/Tools/mingw491_32/bin is default and C:\mingw_x86_64\release7.1.0-posix-dwarf-rt_v5-rev2.7\bin is the correct one.
-------------- Build: 32bit in deneme21 (compiler: MinGW GCC Compiler 32bit)---------------
Checking if target is up-to-date: mingw32-make.exe -q -f Makefile 32bit
Running command: D:/Qt/Qt5.4.1/Tools/mingw491_32/bin/mingw32-make.exe -f "D:/Qt_ws/deneme/deneme31/Makefile" VERBOSE=1 install/strip
C:\CMake3.10.2\win32\bin\cmake.exe -HD:\Qt_ws\deneme\deneme31 -BD:\Qt_ws\deneme\deneme31 --check-build-system CMakeFiles\Makefile.cmake 0
C:\CMake3.10.2\win32\bin\cmake.exe -E cmake_progress_start D:\Qt_ws\deneme\deneme31\CMakeFiles D:\Qt_ws\deneme\deneme31\CMakeFiles\progress.marks
D:/Qt/Qt5.4.1/Tools/mingw491_32/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'D:/Qt_ws/deneme/deneme31'
D:/Qt/Qt5.4.1/Tools/mingw491_32/bin/mingw32-make.exe -f CMakeFiles\deneme21.dir\build.make CMakeFiles/deneme21.dir/depend
mingw32-make.exe[2]: Entering directory 'D:/Qt_ws/deneme/deneme31'
C:\CMake3.10.2\win32\bin\cmake.exe -E cmake_depends "MinGW Makefiles" D:\Qt_ws\deneme\deneme31 D:\Qt_ws\deneme\deneme31 D:\Qt_ws\deneme\deneme31 D:\Qt_ws\deneme\deneme31 D:\Qt_ws\deneme\deneme31\CMakeFiles\deneme21.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory 'D:/Qt_ws/deneme/deneme31'
D:/Qt/Qt5.4.1/Tools/mingw491_32/bin/mingw32-make.exe -f CMakeFiles\deneme21.dir\build.make CMakeFiles/deneme21.dir/build
mingw32-make.exe[2]: Entering directory 'D:/Qt_ws/deneme/deneme31'
[ 50%] Building CXX object CMakeFiles/deneme21.dir/src/foo.cpp.obj
C:\mingw_x86_64\release7.1.0-posix-dwarf-rt_v5-rev2.7\bin\g++.exe #CMakeFiles/deneme21.dir/includes_CXX.rsp -m32 -o CMakeFiles\deneme21.dir\src\foo.cpp.obj -c D:\Qt_ws\deneme\deneme31\src\foo.cpp
[100%] Linking CXX static library libdeneme21.a
C:\CMake3.10.2\win32\bin\cmake.exe -P CMakeFiles\deneme21.dir\cmake_clean_target.cmake
C:\CMake3.10.2\win32\bin\cmake.exe -E cmake_link_script CMakeFiles\deneme21.dir\link.txt --verbose=1
C:\mingw_x86_64\release7.1.0-posix-dwarf-rt_v5-rev2.7\bin\ar.exe qc libdeneme21.a CMakeFiles/deneme21.dir/src/foo.cpp.obj
C:\mingw_x86_64\release7.1.0-posix-dwarf-rt_v5-rev2.7\bin\ranlib.exe libdeneme21.a
mingw32-make.exe[2]: Leaving directory 'D:/Qt_ws/deneme/deneme31'
[100%] Built target deneme21
mingw32-make.exe[1]: Leaving directory 'D:/Qt_ws/deneme/deneme31'
C:\CMake3.10.2\win32\bin\cmake.exe -E cmake_progress_start D:\Qt_ws\deneme\deneme31\CMakeFiles 0
D:/Qt/Qt5.4.1/Tools/mingw491_32/bin/mingw32-make.exe -f CMakeFiles\Makefile2 preinstall
How can I make CodeBlocks use the compiler that I want in cmake created project?

cmake make cannot find -lprotocol

I have these files in the directory:
CMakeLists.txt datalink.c datalink.h protocol.a protocol.h
All these files were got from my teacher except CMakeLists.txt.
#CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(DataLinkSimulator)
INCLUDE_DIRECTORIES(.)
set(SOURCE_FILES datalink.c protocol.a datalink.h protocol.h)
add_executable(DataLinkSimulator ${SOURCE_FILES})
target_link_libraries(DataLinkSimulator protocol.a)
I run 'cmake .' in this directory, and it works.
However, when I run 'make' , it gives me these errors.
Scanning dependencies of target DataLinkSimulator
[ 50%] Building C object CMakeFiles/DataLinkSimulator.dir/datalink.c.o
[100%] Linking C executable DataLinkSimulator
/usr/bin/ld: cannot find -lprotocol
collect2: 错误:ld 返回 1 #(means "error: ld return 1")
CMakeFiles/DataLinkSimulator.dir/build.make:94: recipe for target 'DataLinkSimulator' failed
make[2]: *** [DataLinkSimulator] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DataLinkSimulator.dir/all' failed
make[1]: *** [CMakeFiles/DataLinkSimulator.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The error "cannot find -lprotocol" must caused by ld's mistaking protocol as a shared lib. But my protocol is a static lib. So I am confused.
If I edit makefile by myself instead of using cmake, it works correctly.
datalink: datalink.c datalink.h
gcc datalink.c protocol.a -o datalink -lm -lstdc++ -m32
clean:
${RM} datalink
${RM} *.o
I used a "make VERBOSE=1":
/usr/local/bin/cmake -H/home/shantom/Desktop/FileRecv/Lab1-linux -B/home/shantom/Desktop/FileRecv/Lab1-linux --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/shantom/Desktop/FileRecv/Lab1-linux/CMakeFiles /home/shantom/Desktop/FileRecv/Lab1-linux/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
make -f CMakeFiles/DataLinkSimulator.dir/build.make CMakeFiles/DataLinkSimulator.dir/depend
make[2]: Entering directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
cd /home/shantom/Desktop/FileRecv/Lab1-linux && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/shantom/Desktop/FileRecv/Lab1-linux /home/shantom/Desktop/FileRecv/Lab1-linux /home/shantom/Desktop/FileRecv/Lab1-linux /home/shantom/Desktop/FileRecv/Lab1-linux /home/shantom/Desktop/FileRecv/Lab1-linux/CMakeFiles/DataLinkSimulator.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
make -f CMakeFiles/DataLinkSimulator.dir/build.make CMakeFiles/DataLinkSimulator.dir/build
make[2]: Entering directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
[ 50%] Linking C executable DataLinkSimulator
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/DataLinkSimulator.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/DataLinkSimulator.dir/datalink.c.o -o DataLinkSimulator -Wl,-Bstatic -lprotocol -Wl,-Bdynamic
/usr/bin/ld: cannot find -lprotocol
collect2: 错误:ld 返回 1
CMakeFiles/DataLinkSimulator.dir/build.make:94: recipe for target 'DataLinkSimulator' failed
make[2]: *** [DataLinkSimulator] Error 1
make[2]: Leaving directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DataLinkSimulator.dir/all' failed
make[1]: *** [CMakeFiles/DataLinkSimulator.dir/all] Error 2
make[1]: Leaving directory '/home/shantom/.wine/drive_c/Program Files/QQ/Users/1044950475/FileRecv/Lab1-linux'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
In order to understand the error you need to launch make command from the command line using verbose mode; on Linux paltform it means launching:
make VERBOSE=1
In this manner you will have the entire command line used to compile the code.
In order to resolve your error you could:
add a link_directories(directory_where_you_have_library) CMake line adding the directory where you have protocol.a before target_link_libraries line
add protocol.a with absolute path.
Your modified Makefile works because probably you have it in the same directory of all the files while CMake creates many Makefiles in various directories starting from build root directory so it needs -L gcc flags (obtainable through link_directories) or -l with absolute path (obtainable adding protocol.a with absolute path).

unable to include a ui_form header of QT5 in cmake

My CMakeLists.txt looks something like :
cmake_minimum_required(VERSION 2.8)
if(CMAKE_BUILD_TYPE STREQUAL Release)
SET(CMAKE_BUILD_TYPE Release)
SET (PROJECT_NAME location_recognition)
message("Release mode")
else()
SET(CMAKE_BUILD_TYPE Debug)
SET (PROJECT_NAME location_recognition)
SET(CMAKE_CXX_FILES "-g -Wall")
message("Debug mode")
endif()
#find QT libraries
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Boost REQUIRED)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
# We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
add_definitions(${Qt5Widgets_DEFINITIONS})
SET(SRC
src/voting_classifier.cpp
src/voting_classifier_helper.cpp
src/results_scene.cpp
src/image_window_widget.cpp
src/image_result_matrix.cpp
src/location_recognition.cpp
src/main.cpp
)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
FIND_PROGRAM(QT_UIC_EXECUTABLE uic
$ENV{QTDIR}/bin
)
IF (QT_UIC_EXECUTABLE)
# SET ( QT_WRAP_UI "YES")
message("WOW")
ENDIF (QT_UIC_EXECUTABLE)
QT5_WRAP_UI(image_result_matrix.h ui_forms/image_result_matrix.ui -o ui_forms/image_result_matrix.h)
QT5_WRAP_UI(image_window_widget.h ui_forms/image_window_widget.ui -o ui_forms/image_window_widget.h)
QT5_WRAP_UI(location_recognition.h ui_forms/location_recognition.ui -o ui_forms/location_recognition.h)
QT5_WRAP_UI(ui_results_view.h ui_forms/result_view.ui -o ui_forms/ui_results_view.h)
include_directories(${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/ui_forms
${PROJECT_SOURCE_DIR}
${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/../perception_kit/utilities/include
${PROJECT_SOURCE_DIR}/../perception_kit/visual_categorization/include
${OpenCV_INCLUDE_DIRS})
FIND_LIBRARY(utilities NAMES libperception_kitutilities.so PATHS "/other/workspace/perception/perception_kit/utilities/lib")
FIND_LIBRARY(utilitiesd NAMES libperception_kitutilitiesd.so PATHS "/other/workspace/perception/perception_kit/utilities/lib")
message("Utilites Libs :${utilities}")
FIND_LIBRARY(visual_categorization NAMES libperception_kitvisual_categorization.so PATHS "/other/workspace/perception/perception_kit/visual_categorization/lib")
FIND_LIBRARY(visual_categorizationd NAMES libperception_kitvisual_categorizationd.so PATHS "/other/workspace/perception/perception_kit/visual_categorization/lib")
message("Visual_categorization Libs :${visual_categorization}")
SET(LINK_LIBRARY optimized ${utilities} ${visual_categorization} debug ${utilities} ${visual_categorizationd})
# set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${perception_kit_VERSION} )
add_executable(location_recognition ${SRC})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY}
${OpenCV_LIBS} ${Boost_LIBS})
qt5_use_modules(location_recognition Core Gui Widgets)
when i do
cmake .
it does fine. But when I try make it still says that the ui_forms/*.h header not found and it fails.
In file included from
/other/workspace/perception/location_recognition/src/results_scene.cpp:4:0:
/other/workspace/perception/location_recognition/include/perception_kit/location_recognition/results_scene.h:6:29:
fatal error: ui_results_view.h: No such file or directory compilation
terminated. make[2]: *
[CMakeFiles/location_recognition.dir/src/results_scene.cpp.o] Error 1
make[1]: * [CMakeFiles/location_recognition.dir/all] Error 2 make:
* [all] Error 2
when i do `make VERBOSE=1'
I get
/usr/local/bin/cmake -H/other/workspace/perception/location_recognition -B/other/workspace/perception/location_recognition --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /other/workspace/perception/location_recognition/CMakeFiles /other/workspace/perception/location_recognition/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition_automoc.dir/build.make CMakeFiles/location_recognition_automoc.dir/depend
make[2]: Entering directory `/other/workspace/perception/location_recognition'
cd /other/workspace/perception/location_recognition && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition/CMakeFiles/location_recognition_automoc.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition_automoc.dir/build.make CMakeFiles/location_recognition_automoc.dir/build
make[2]: Entering directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles 9
[ 11%] Automoc for target location_recognition
/usr/local/bin/cmake -E cmake_automoc /other/workspace/perception/location_recognition/CMakeFiles/location_recognition_automoc.dir/
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/voting_classifier.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/voting_classifier_helper.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/results_scene.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/image_window_widget.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/image_result_matrix.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/location_recognition.cpp
AUTOMOC: Checking /other/workspace/perception/location_recognition/src/main.cpp
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles 9
[ 11%] Built target location_recognition_automoc
make -f CMakeFiles/location_recognition.dir/build.make CMakeFiles/location_recognition.dir/depend
make[2]: Entering directory `/other/workspace/perception/location_recognition'
cd /other/workspace/perception/location_recognition && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition /other/workspace/perception/location_recognition/CMakeFiles/location_recognition.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make -f CMakeFiles/location_recognition.dir/build.make CMakeFiles/location_recognition.dir/build
make[2]: Entering directory `/other/workspace/perception/location_recognition'
/usr/local/bin/cmake -E cmake_progress_report /other/workspace/perception/location_recognition/CMakeFiles 3
[ 22%] Building CXX object CMakeFiles/location_recognition.dir/src/results_scene.cpp.o
/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -O3 -DNDEBUG -fPIE -I/other/workspace/perception/location_recognition -I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include -I/other/workspace/perception/location_recognition/include -I/other/workspace/perception/location_recognition/ui_forms -I/other/Qt5.0.1/5.0.1/gcc_64/include -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtWidgets -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtGui -I/other/Qt5.0.1/5.0.1/gcc_64/include/QtCore -I/other/Qt5.0.1/5.0.1/gcc_64/mkspecs/linux-g++-64 -I/other/workspace/perception/location_recognition/../perception_kit/utilities/include -I/other/workspace/perception/location_recognition/../perception_kit/visual_categorization/include -o CMakeFiles/location_recognition.dir/src/results_scene.cpp.o -c /other/workspace/perception/location_recognition/src/results_scene.cpp
In file included from /other/workspace/perception/location_recognition/src/results_scene.cpp:4:0:
/other/workspace/perception/location_recognition/include/perception_kit/location_recognition/results_scene.h:6:29: fatal error: ui_results_view.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/location_recognition.dir/src/results_scene.cpp.o] Error 1
make[2]: Leaving directory `/other/workspace/perception/location_recognition'
make[1]: *** [CMakeFiles/location_recognition.dir/all] Error 2
make[1]: Leaving directory `/other/workspace/perception/location_recognition'
make: *** [all] Error 2
So, somehow it is either able to create the ui_form header or its not linking properly.
I spent quite sometime experimenting with QT_WRAP_UI and QT5_WRAP_UI but couldn't solve the issue.
What should change in my CMakeLists.txt to get the ui_form headers included correctly ?
You misused qt5_wrap_ui macro. According to the documentation, it has the following parameters
qt5_wrap_ui(outfiles inputfile ... OPTIONS ...)
In your example, this become:
qt5_wrap_ui(UIS_HDRS
ui_forms/image_result_matrix.ui
ui_forms/image_window_widget.ui
ui_forms/location_recognition.ui
ui_forms/ui_results_view.ui
)
The command will configure your project to process *.ui files into valid C++ ui_XXXX.h and save their path to the list named UIS_HDRS. This allows you to use them as input of a target declared later:
add_executable(location_recognition ${SRC} ${UIS_HDRS})
Note: ui_XXXX.h files are generated in the build directory ${CMAKE_CURRENT_BINARY_DIR}.