我有以下项目文件结构:
libs/
└──FreeImage/
├── FreeImage.dll
├── FreeImage.h
├── FreeImage.lib
├── license-fi.txt
├── license-gplv2.txt
└── license-gplv3.txt
main.cpp
CMakeLists.txt
我的CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.4)
project(untitled)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(FREEIMAGE_LIBRARY_AND_HEADER_DIRECTORY libs/FreeImage)
find_path(FREEIMAGE_LIBRARY_AND_HEADER_DIRECTORY FreeImage.h)
find_library(FREEIMAGE_LIBRARY_AND_HEADER_DIRECTORY freeimage)
include_directories(${FREEIMAGE_LIBRARY_AND_HEADER_DIRECTORY})
set(SOURCE_FILES main.cpp)
add_executable(main ${SOURCE_FILES})
target_link_libraries(main freeimage)
我按照这个来写我的CMakeLists.txt
,但它对我不起作用。
输出:
/home/username/main_ssd/soft/linux/portable/clion-140.569.17/bin/cmake/bin/cmake --build /home/username/.clion10/system/cmake/generated/70336599/70336599/Debug --target main -- -j 4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/username/.clion10/system/cmake/generated/70336599/70336599/Debug
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
Linking CXX executable main
/usr/bin/ld: cannot find -lfreeimage
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:85: recipe for target 'main' failed
make[3]: *** [main] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/main.dir/all' failed
make[2]: *** [CMakeFiles/main.dir/all] Error 2
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/main.dir/rule' failed
make[1]: *** [CMakeFiles/main.dir/rule] Error 2
Makefile:160: recipe for target 'main' failed
make: *** [main] Error 2