Hello! This is my first post here!
I am trying to do my first project with CMake and I am stuck. I am working with windows.
Please, can you help me?
Currently, there are two issues:
- I am trying to include an external library called GCLib, but CMake does not find it.
- If I copy the library to the output folder then a message appears telling me that there are undefined symbols. I included gc.h but (I suppose) the linker is not linking them properly:
Severity Code Description Project File Line Suppression State
Error LNK1120 2 unresolved externals C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.exe 1
Error LNK2019 unresolved external symbol __imp_GC_init referenced in function main C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.cpp.obj 1
Error LNK2019 unresolved external symbol __imp_GC_malloc referenced in function main C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.cpp.obj 1
My current file list:
My current CMakeList is:
CMakeList.txt : CMake project for multiDimIndex, include source and define
project specific logic here.
project(multiDimIndex)
cmake_minimum_required (VERSION 3.8)
message(STATUS “--------------------- Testing”)Add source to this project’s executable.
message("---- CMAKE_SOURCE_DIR = " ${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/gclib)
link_directories(${CMAKE_SOURCE_DIR}/gclib)
find_path(GCLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/gclib/gc.h)
find_library(GCLIB_LIBRARY gc-lib)message (“-- " ${CMAKE_SOURCE_DIR}/gclib/gc.h)
message(”-- " ${GCLIB_INCLUDE_DIR})
message("-- " ${GCLIB_LIBRARY})
set(YOUR_LIBRARIES)if (GCLIB_INCLUDE_DIR AND GCLIB_LIBRARY)
# you may need that if further action in your CMakeLists.txt depends
# on detecting your library
set(GCLIB_FOUND TRUE)# you may need that if you want to conditionally compile some parts # of your code depending on library availability add_definitions(-DHAVE_GCLIB=1) # those two, you really need include_directories(${GCLIB_INCLUDE_DIR}) set(YOUR_LIBRARIES ${YOUR_LIBRARIES} ${GCLIB_LIBRARY})
endif ()
configure_file(multiDimIndex.config.h.in multiDimIndex.config.h) #fichero donde poner configuraciones para el proyecto ()
add_library(format format.cpp)
add_executable (multiDimIndex “multiDimIndex.cpp” “multiDimIndex.h” ) #“…/PruebaGC/include/gc.h”) “./gc-lib/gc.h”
#target_link_libraries(multiDimIndex ${YOUR_LIBRARIES})
set(YOUR_LIBRARIES ${YOUR_LIBRARIES} format)
message ("=== libraries " ${YOUR_LIBRARIES})
target_link_libraries(multiDimIndex ${YOUR_LIBRARIES})
#target_link_libraries(multiDimIndex gc-lib format)target_include_directories(multiDimIndex PUBLIC
“${PROJECT_BINARY_DIR}”
)
When CMake is run, this is the output:
2> CMake generation started for configuration: ‘x64-Debug’.
2> Command line: “cmd.exe” /c ““C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe” -G “Ninja” -DCMAKE_INSTALL_PREFIX:PATH=“C:\multiDimIndex\out\install\x64-Debug” -DCMAKE_CXX_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE_C_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE_BUILD_TYPE=“Debug” -DCMAKE_MAKE_PROGRAM=“C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe” “C:\multiDimIndex” 2>&1”
2> Working directory: C:\multiDimIndex\out\build\x64-Debug
2> [CMake] – --------------------- Testing
2> [CMake] ---- CMAKE_SOURCE_DIR = C:/multiDimIndex
2> [CMake] – C:/multiDimIndex/gclib/gc.h
2> [CMake] – GCLIB_INCLUDE_DIR-NOTFOUND
2> [CMake] – GCLIB_LIBRARY-NOTFOUND
2> [CMake] === librerías format
2> [CMake] – Configuring done
2> [CMake] – Generating done
2> [CMake] – Build files have been written to: C:/multiDimIndex/out/build/x64-Debug
2> [CMake]
2> Extracted includes paths.
2> Extracted CMake variables.
2> Extracted source files and headers.
2> Extracted code model.
2> CMake generation finished.
Thank in advance!