Unable to build FreeRTOS WIN32 demo in Clion - cmake

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.

Related

Linking problems with yaml-cpp

I am trying to incorporate yaml-cpp into my project.
I have a "Demes" class where I need to parse a YAML file.
This is the relevant method in Demes.cpp:
#include "Demes.hpp"
void Demes::parse(const std::string& fileName)
{
YAML::Node test = YAML::LoadFile(fileName);
}
where Demes.hpp includes the yaml-cpp headers and declares the 'parse' method.
Building with make -VERBOSE=1 (as suggested by #Tsyvarev) gives:
[100%] Linking CXX executable momentspp
cd /home/gvbarroso/Devel/momentspp/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/momentspp.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native CMakeFiles/momentspp.dir/Log.cpp.o CMakeFiles/momentspp.dir/PolymorphismData.cpp.o CMakeFiles/momentspp.dir/SumStatsLibrary.cpp.o CMakeFiles/momentspp.dir/Drift.cpp.o CMakeFiles/momentspp.dir/Migration.cpp.o CMakeFiles/momentspp.dir/Mutation.cpp.o CMakeFiles/momentspp.dir/Recombination.cpp.o CMakeFiles/momentspp.dir/Epoch.cpp.o CMakeFiles/momentspp.dir/Model.cpp.o CMakeFiles/momentspp.dir/OptimizationWrapper.cpp.o CMakeFiles/momentspp.dir/Demes.cpp.o CMakeFiles/momentspp.dir/main.cpp.o -o momentspp -Wl,-rpath,/home/gvbarroso/.local/lib: /home/gvbarroso/.local/lib/libbpp-phyl3.so.1.0.0 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.74.0 /home/gvbarroso/.local/lib/libbpp-seq3.so.1.0.0 /home/gvbarroso/.local/lib/libbpp-core3.so.1.0.0
/usr/bin/ld: CMakeFiles/momentspp.dir/Demes.cpp.o: in function Demes::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Demes.cpp:(.text+0x4c): undefined reference to YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
/usr/bin/ld: Demes.cpp:(.text+0x12c): undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/momentspp.dir/build.make:277: src/momentspp] Error 1
make[2]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make[1]: *** [CMakeFiles/Makefile2:125: src/CMakeFiles/momentspp.dir/all] Error 2
make[1]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make: *** [Makefile:156: all] Error 2
I am using CMake to build my project, but I am still fairly unfamiliar with it.
EDIT: I forgot to mention that I have two CMakeLists.txt files, one inside src and the other inside the external build.
The start of my CMakeLists.txt file in the external build is:
cmake_minimum_required (VERSION 3.5.0)
project (momentspp CXX)
SET(CMAKE_CXX_FLAGS "-std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native")
And the part of it where I look for yaml-cpp is:
FIND_PACKAGE(yaml-cpp REQUIRED)
IF(yaml-cpp_FOUND)
INCLUDE_DIRECTORIES(${yaml-cpp_INCLUDE_DIRS})
SET(LIBS {yaml-cpp_LIBRARIES})
MESSAGE("-- yaml-cpp libraries found here:")
MESSAGE(" includes: ${yaml-cpp_INCLUDE_DIRS}")
ENDIF()
My full CMakeLists.txt file inside src is:
SET(momentspp_CPP
Log.cpp
PolymorphismData.cpp
SumStatsLibrary.cpp
Drift.cpp
Migration.cpp
Mutation.cpp
Recombination.cpp
Epoch.cpp
Model.cpp
OptimizationWrapper.cpp
Demes.cpp
main.cpp
)
ADD_EXECUTABLE (momentspp ${momentspp_CPP})
SET(momentspp-targets momentspp)
FOREACH (target ${momentspp-targets})
TARGET_LINK_LIBRARIES(${target} ${BPP_LIBS_SHARED} ${BOOST_LIBS_SHARED} ${EIGEN3_LIBS_SHARED} ${yaml-cpp_LIBS_SHARED})
TARGET_LINK_LIBRARIES (${target} ${LIBS})
ENDFOREACH (target)
INSTALL(TARGETS ${momentspp-targets} DESTINATION ${CMAKE_INSTALL_BINDIR})
and this was working prior to the inclusion of yaml-cpp.
This feels like a rather complicated CMake set-up, but I am copying and editing it from a previous project where someone else helped me with it.
How can I fix the linking issue?
I tried looking similar questions around here, but couldn't get their solutions to work for me (apparently those people where not using CMake to build their projects).
Thank you,
Gustavo

CMake and vcpkg linker error and crazy naming

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

cmake 3.10 cant internally test the blas library

I cant get working my blas library with cmake. I have arch-linxux, both blas and cmake are installed with pacman. Cant understand where is problem :-(. I made cmake to print out the output of macro CHECK_FORTRAN_FUNCTION_EXISTS, because it fails there. Maybe I dont have proper configuration of ld?
My simple testing CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(Test C Fortran)
find_package(BLAS)
Error part from output:
-- Looking for Fortran sgemm
-- Change Dir: /home/jiri/test_lapack/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_486fc/fast"
/usr/bin/make -f CMakeFiles/cmTC_486fc.dir/build.make CMakeFiles/cmTC_486fc.dir/build
make[1]: Entering directory '/home/jiri/test_lapack/CMakeFiles/CMakeTmp'
Building Fortran object CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o
/usr/bin/gfortran -c /home/jiri/test_lapack/CMakeFiles/CMakeTmp/testFortranCompiler.f -o CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o
Linking Fortran executable cmTC_486fc
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_486fc.dir/link.txt --verbose=1
/usr/bin/gfortran CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o -o cmTC_486fc /usr/local/lib64/libblas.a
/usr/bin/ld: /usr/local/lib64/libblas.a(sgemm.f.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib64/libblas.a(xerbla.f.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_486fc.dir/build.make:99: cmTC_486fc] Error 1
make[1]: Leaving directory '/home/jiri/test_lapack/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_486fc/fast] Error 2
-- Looking for Fortran sgemm - not found

handmade Makefile to Cmake with static library

Here is a MakeFile for my project, since I'm using CLion for as my IDE, I need a Cmake configuration. I could not convert the following Makefile correctly.
all: VisualCryptography
VisualCryptography: VisualCryptographyGPU.o VisualCryptographyMC.o ExtVisualCryptographyCPU.o ExtVisualCryptographyGPU.o ExtVisualCryptographyMC.o VisualCryptographyCPUTest.o
g++ *.o -L/usr/local/cuda/lib64 -lcudart -lpthread ./lib/libVC.a -o VisualCryptography
rm -rf *.o
VisualCryptographyMC.o: ./source/VisualCryptographyMC.c
g++ -lpthread -c ./source/VisualCryptographyMC.c
VisualCryptographyCPUTest.o: ./source/VisualCryptographyCPUTest.c
g++ -lpthread -c ./source/VisualCryptographyCPUTest.c
VisualCryptographyGPU.o: ./source/VisualCryptographyGPU.cu
/usr/local/cuda/bin/nvcc -c -arch=compute_20 -code=sm_20 -lm ./source/VisualCryptographyGPU.cu
ExtVisualCryptographyCPU.o: ./source/ExtVisualCryptographyCPU.c
g++ -c ./source/ExtVisualCryptographyCPU.c
ExtVisualCryptographyGPU.o: ./source/ExtVisualCryptographyGPU.cu
/usr/local/cuda/bin/nvcc -c -arch=compute_20 -code=sm_20 -lm ./source/ExtVisualCryptographyGPU.cu
ExtVisualCryptographyMC.o: ./source/ExtVisualCryptographyMC.c
g++ -lpthread -c ./source/ExtVisualCryptographyMC.c
clean:
rm -rf *.o VisualCryptography
Here is my CMakeList.txt file:
cmake_minimum_required(VERSION 3.7)
project(VC)
set(CMAKE_CXX_STANDARD 11)
find_package (Threads)
find_package(CUDA REQUIRED)
link_directories(${CMAKE_BINARY_DIR}/lib)
set(SOURCE_FILES
source/common.h
source/ExtVisualCryptographyGPU.cu
source/ExtVisualCryptographyCPU.c
source/ExtVisualCryptographyMC.c
source/preprocess.h
source/VisualCryptographyCPUDefault.h
source/VisualCryptographyCPUTest.c
source/VisualCryptographyCPUTest.h
source/VisualCryptographyMC.c
source/VisualCryptographyGPU.cu
source/VisualCryptographyGPU.h
source/VisualCryptographyMC.h)
add_executable(VC ${SOURCE_FILES})
target_link_libraries(VC ${CMAKE_THREAD_LIBS_INIT} libVC.a)
Where am I doing wrong?
This is the error that I'm getting:
/usr/bin/ld: cannot find -lVC
collect2: error: ld returned 1 exit status
CMakeFiles/VC.dir/build.make:172: recipe for target 'VC' failed
make[3]: *** [VC] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/VC.dir/all' failed
make[2]: *** [CMakeFiles/VC.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/VC.dir/rule' failed
make[1]: *** [CMakeFiles/VC.dir/rule] Error 2
Makefile:118: recipe for target 'VC' failed
make: *** [VC] Error 2
I also should note that the libVC.a is in lib sub dir of my project, and all other source codes are in source sub dir. the main function is also in libVC.a, which is static.
Try changing the name as oLen suggested, this behavior is seen in some versions of Cmake. You can check another version if you insist on using the same name.

cmake package_search_module for glfw3 finds package, doesn't supply full lib path

This seems pretty straightforward but I'm wasting enormous amounts of time getting it working. I just want to build and link a main.cpp file that includes glfw3.h, but cmake is not seeing the lib path for GLFW. the call to package_search_module is providing the right include dir, but the resulting GLFW_LIBRARIES value only has the lib name 'glfw3' in it and its dir is not being given on the command line for the build.
What am I missing here?
Here is my very simple CMakeFiles.txt:
cmake_minimum_required(VERSION 3.3)
project(gltest)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gltest ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(gltest ${GLFW_LIBRARIES})
message("GLFW_LIBRARIES=${GLFW_LIBRARIES}")
And here is the build output, where you can see at the top there that GLFW_LIBRARIES contains 'glfw3':
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --target all -- -j 8
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/dave/dev/gltest -B/Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
GLFW_LIBRARIES=glfw3
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/depend
cd /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/dave/dev/gltest /Users/dave/dev/gltest /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/gltest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/build
[ 50%] Linking CXX executable gltest
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/gltest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++11 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/gltest.dir/main.cpp.o -o gltest -lglfw3
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gltest] Error 1
make[1]: *** [CMakeFiles/gltest.dir/all] Error 2
make: *** [all] Error 2
And, finally, here is the glfw3.pc pkg-config that is used for the pkg_search_module call:
prefix=/usr/local/Cellar/glfw3/3.2.1
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: GLFW
Description: A multi-platform library for OpenGL, window and input
Version: 3.2.1
URL: http://www.glfw.org/
Requires.private:
Libs: -L${libdir} -lglfw3
Libs.private: -framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo
Cflags: -I${includedir}
~
Update: I got it working with this, but it still feels wrong
cmake docs recommend against using link_directories, but I am able to make this work by using that and building up a list of link libraries:
set(LINK_LIBRARIES )
# GLFW lib
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
link_directories(${GLFW_LIBRARY_DIRS})
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${GLFW_LIBRARIES})
add_executable(gltest ${SOURCE_FILES})
target_link_libraries(gltest ${LINK_LIBRARIES})
You need <XPREFIX>_LDFLAGS (all required linker flag) and maybe <XPREFIX>_LDFLAGS_OTHER (all other linker flags) with <XPREFIX> = GLFW, acccording to the documentation https://cmake.org/cmake/help/v3.6/module/FindPkgConfig.html