I've got following project file structure :
libs/
└──FreeImage/
├── FreeImage.dll
├── FreeImage.h
├── FreeImage.lib
├── license-fi.txt
├── license-gplv2.txt
└── license-gplv3.txt
main.cpp
CMakeLists.txt
My 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)
I followed this to write my CMakeLists.txt
, but it doesn't work for me.
The output:
/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
set(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY libs/FreeImage)
Variable FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY
is set to libs/FreeImage
find_path(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY FreeImage.h)
Variable FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY
is set to directory containing the named file FreeImage.h
. No hints to the commands are present, because of missing optional arguments PATHS or HINTS
find_library(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY freeimage)
Variable FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY
is set to full path to the library FreeImage
(if found). No hints to the commands are present, because of missing optional arguments PATHS or HINTS
include_directories(${FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY})
Variable FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY
contains full path to library FreeImage
(if found).
target_link_libraries(main freeimage)
No target with name freeimage
exists in the CMakeLists.txt and hence it is interpreted that you want to link -lfreeimage
Question: Why do you try to use a "dll" on Linux?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With