我只想将Lemon库添加到我的CMakeLists.txt中。当我没有使用CMake时,我只添加了“-lemon”,一切都很顺利,但现在我不知道将其添加到CMake文件的过程。
已编辑包含我的 CMakeLists.txt :
# Created by the script cgal_create_cmake_script_with_options
# This is the CMake script for compiling a set of CGAL applications.
project( ssp )
cmake_minimum_required(VERSION 2.6.2)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
cmake_policy(VERSION 2.8.4)
else()
cmake_policy(VERSION 2.6)
endif()
endif()
set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
if ( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif()
# CGAL and its components
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# include helper file
include( ${CGAL_USE_FILE} )
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
set(CMAKE_CXX_FLAGS "-lemon")
# Creating entries for target: ssp
# ############################
add_executable( ssp arrangement.cpp main.cpp polygonOperations.cpp scheduleGraph.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS ssp )
# Link the executable to CGAL and third-party libraries
target_link_libraries(ssp lemon ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
答案 0 :(得分:2)
这很简单,请使用target_link_libraries:
project(test)
add_executable(mine test.c)
target_link_libraries(mine m)
在这个例子中,我正在链接libm。在您的情况下,m
将是lemon
。至少我认为,我不确定您的问题库名称是lemon
还是emon
,因为-l
是标志,名称应该跟随(-lm
链接libm)。
对于我的简单示例,如果我运行make VERBOSE=1
(并删除不重要的行):
[100%] Building C object CMakeFiles/mine.dir/test.c.o
/usr/bin/cc -o CMakeFiles/mine.dir/test.c.o -c /home/tgallagher/temp/test.c
Linking C executable mine
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/mine.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/mine.dir/test.c.o -o mine -rdynamic -lm
因此,它首先编译源文件,然后将-lm
放在链接器行上。