我一直在尝试使用 CMake 将 OpenImageIO 链接到可执行文件,但在构建的链接阶段不断出现错误。有谁知道如何正确设置 CMakeLists.txt 以便库链接?
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(VolumeFX)
add_compile_options(-std=c++11)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories("/usr/local/include")
find_library(OIIO "OpenImageIO" "/usr/local/lib")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
include_directories("/group/dpa/include")
find_library(OIIO "OpenImageIO")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(SOURCE_FILES
main.cpp
Vector.h
Camera.cpp
Camera.h
FloatVolume.h
SphereVolume.cpp
SphereVolume.h
ClampMin.cpp
ClampMin.h
Renderer.cpp
Renderer.h
Image.cpp
Image.h
OIIOFiles.cpp
OIIOFiles.h)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(${PROJECT_NAME} ${OIIO})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${PROJECT_NAME} ${OIIO})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
这是运行make文件的输出...
Scanning dependencies of target VolumeFX
[ 14%] Building CXX object CMakeFiles/VolumeFX.dir/main.cpp.o
[ 28%] Building CXX object CMakeFiles/VolumeFX.dir/Camera.cpp.o
[ 42%] Building CXX object CMakeFiles/VolumeFX.dir/SphereVolume.cpp.o
[ 57%] Building CXX object CMakeFiles/VolumeFX.dir/ClampMin.cpp.o
[ 71%] Building CXX object CMakeFiles/VolumeFX.dir/Renderer.cpp.o
[ 85%] Building CXX object CMakeFiles/VolumeFX.dir/Image.cpp.o
[100%] Building CXX object CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o
Linking CXX executable VolumeFX
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `lux::writeOIIOImage(char const*, lux::Image&, float, float)':
OIIOFiles.cpp:(.text+0x345): undefined reference to `OpenImageIO::v1_5::ImageOutput::create(std::string const&, std::string const&)'
OIIOFiles.cpp:(.text+0x435): undefined reference to `OpenImageIO::v1_5::ImageSpec::ImageSpec(int, int, int, OpenImageIO::v1_5::TypeDesc)'
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `lux::writeOIIOImage(char const*, lux::Image&, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&, float, float)':
OIIOFiles.cpp:(.text+0x18a7): undefined reference to `OpenImageIO::v1_5::ImageOutput::create(std::string const&, std::string const&)'
OIIOFiles.cpp:(.text+0x1997): undefined reference to `OpenImageIO::v1_5::ImageSpec::ImageSpec(int, int, int, OpenImageIO::v1_5::TypeDesc)'
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `lux::readOIIOImage(char const*, lux::Image&)':
OIIOFiles.cpp:(.text+0x2b8b): undefined reference to `OpenImageIO::v1_5::ImageInput::create(std::string const&, std::string const&)'
OIIOFiles.cpp:(.text+0x2c14): undefined reference to `OpenImageIO::v1_5::ImageSpec::ImageSpec(OpenImageIO::v1_5::TypeDesc)'
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `lux::readOIIOImage(char const*, lux::Image&, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >&)':
OIIOFiles.cpp:(.text+0x3011): undefined reference to `OpenImageIO::v1_5::ImageInput::create(std::string const&, std::string const&)'
OIIOFiles.cpp:(.text+0x309a): undefined reference to `OpenImageIO::v1_5::ImageSpec::ImageSpec(OpenImageIO::v1_5::TypeDesc)'
OIIOFiles.cpp:(.text+0x339e): undefined reference to `OpenImageIO::v1_5::ImageSpec::metadata_val(OpenImageIO::v1_5::ParamValue const&, bool) const'
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `OpenImageIO::v1_5::ParamValue::~ParamValue()':
OIIOFiles.cpp:(.text._ZN11OpenImageIO4v1_510ParamValueD2Ev[_ZN11OpenImageIO4v1_510ParamValueD5Ev]+0x14): undefined reference to `OpenImageIO::v1_5::ParamValue::clear_value()'
CMakeFiles/VolumeFX.dir/OIIOFiles.cpp.o: In function `OpenImageIO::v1_5::ImageSpec::attribute(OpenImageIO::v1_5::string_view, OpenImageIO::v1_5::string_view)':
OIIOFiles.cpp:(.text._ZN11OpenImageIO4v1_59ImageSpec9attributeENS0_11string_viewES2_[_ZN11OpenImageIO4v1_59ImageSpec9attributeENS0_11string_viewES2_]+0x1c): undefined reference to `OpenImageIO::v1_5::string_view::c_str() const'
OIIOFiles.cpp:(.text._ZN11OpenImageIO4v1_59ImageSpec9attributeENS0_11string_viewES2_[_ZN11OpenImageIO4v1_59ImageSpec9attributeENS0_11string_viewES2_]+0x66): undefined reference to `OpenImageIO::v1_5::ImageSpec::attribute(OpenImageIO::v1_5::string_view, OpenImageIO::v1_5::TypeDesc, void const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [VolumeFX] Error 1
make[1]: *** [CMakeFiles/VolumeFX.dir/all] Error 2
make: *** [all] Error 2