\- lib
CMakeLists.txt
libA.a
libB.a
\- src
\- mod1
\- mod2
\- inc
\- mod1
\- mod2
\- libA
\- libB
\- examples
\- common_inc // common includes for all examples
\- my_executable
CMakeLists.txt
\- src
\- inc
src contains .cpp files for mod1 and mod2, both depend on libA, libB, inc contains headers for libA, libB, and for mod1 and mod2
The question is:
I want to make one shared library which contains libA.a, libB.a and also my src (mod1 and mod2), how I can achieve that?
Is there any other way besides creating static lib (lets call it libMy) from mod1 and mod2 and then link all 3 libs (libMy, libA, libB) into one shared library?
I came up with following CMakeLists.txt but it cannot find -llibA and -llibB
cmake_minimum_required (VERSION 3.5)
project (libMy CXX)
set (CMAKE_CXX_STANDARD 14)
set (SRC
"src/mod1/a1.cpp"
"src/mod2/a2.cpp"
)
set (INC
"inc/mod1/a1.hpp"
"inc/mod2/a2.hpp"
"inc/lib1/libA.hpp"
"inc/lib2/libB.hpp"
)
add_library(libMy STATIC ${SRC} ${INC})
target_include_directories(libMy PUBLIC inc)
add_library(master_library SHARED
dummy.cpp
)
target_link_libraries(master_library libMy)
target_link_libraries(master_library -lpthread)
target_link_libraries(master_library libA.a)
target_link_libraries(master_library libB.a)
UPDATE
Thanks to #Tsyvarev I managed to solve this problem. But there is another one...
When I try to link my shared library into my_executable I get undefined reference error, here is full error message:
../../../lib/libmylib.a(session.cpp.o): In function `mylib::network::session::write(mylib::network::packet const&)':
session.cpp:(.text+0x4e5): undefined reference to `libA::tcp_client::async_write(libA::tcp_client::write_request const&)'
../../../lib/libmylib.a(tcp_server.cpp.o): In function `mylib::network::tcp_server::tcp_server()':
tcp_server.cpp:(.text+0x24b): undefined reference to `libA::tcp_server::tcp_server()'
../../../lib/libmylib.a(tcp_server.cpp.o): In function `mylib::network::tcp_server::~tcp_server()':
tcp_server.cpp:(.text+0x323): undefined reference to `libA::tcp_server::~tcp_server()'
../../../lib/libmylib.a(tcp_server.cpp.o): In function `mylib::network::tcp_server::start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)::{lambda(std::shared_ptr<libA::tcp_client> const&)#1}::operator()(std::shared_ptr<libA::tcp_client> const&) const':
tcp_server.cpp:(.text+0x445): undefined reference to `libA::tcp_client::async_read(libA::tcp_client::read_request const&)'
../../../lib/libmylib.a(tcp_server.cpp.o): In function `mylib::network::tcp_server::start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)':
tcp_server.cpp:(.text+0x52c): undefined reference to `libA::tcp_server::start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, std::function<bool (std::shared_ptr<libA::tcp_client> const&)> const&)'
../../../lib/libmylib.a(tcp_server.cpp.o): In function `mylib::network::tcp_server::on_new_message(std::shared_ptr<libA::tcp_client> const&, libA::tcp_client::read_result const&)':
tcp_server.cpp:(.text+0x767): undefined reference to `libA::tcp_client::async_read(libA::tcp_client::read_request const&)'
tcp_server.cpp:(.text+0x801): undefined reference to `libA::tcp_client::disconnect(bool)'
../../../lib/libmylib.a(pool.cpp.o): In function `mylib::libB::pool::~pool()':
pool.cpp:(.text+0x42): undefined reference to `ConnectionPool_free'
pool.cpp:(.text+0x5f): undefined reference to `URL_free'
../../../lib/libmylib.a(pool.cpp.o): In function `mylib::libB::pool::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
pool.cpp:(.text+0x249): undefined reference to `URL_new'
pool.cpp:(.text+0x26a): undefined reference to `ConnectionPool_new'
pool.cpp:(.text+0x284): undefined reference to `Exception_stack'
pool.cpp:(.text+0x28b): undefined reference to `pthread_getspecific'
pool.cpp:(.text+0x298): undefined reference to `Exception_stack'
pool.cpp:(.text+0x2a9): undefined reference to `pthread_setspecific'
pool.cpp:(.text+0x2e3): undefined reference to `ConnectionPool_start'
pool.cpp:(.text+0x2f8): undefined reference to `Exception_stack'
pool.cpp:(.text+0x2ff): undefined reference to `pthread_getspecific'
pool.cpp:(.text+0x30c): undefined reference to `Exception_stack'
pool.cpp:(.text+0x316): undefined reference to `pthread_setspecific'
pool.cpp:(.text+0x325): undefined reference to `SQLException'
pool.cpp:(.text+0x39d): undefined reference to `Exception_throw'
../../../lib/libmylib.a(connection.cpp.o): In function `mylib::libB::connection::connection(ConnectionPool_S*)':
connection.cpp:(.text+0x18): undefined reference to `ConnectionPool_getConnection'
../../../lib/libmylib.a(connection.cpp.o): In function `mylib::libB::connection::~connection()':
connection.cpp:(.text+0x41): undefined reference to `Connection_close'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::query(Connection_S*, char const*)':
query.cpp:(.text+0x28): undefined reference to `Connection_prepareStatement'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::set(int)':
query.cpp:(.text+0x93): undefined reference to `PreparedStatement_setInt'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::set(char const*)':
query.cpp:(.text+0xe3): undefined reference to `PreparedStatement_setString'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::get_int()':
query.cpp:(.text+0x15d): undefined reference to `ResultSet_getInt'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::get_str[abi:cxx11]()':
query.cpp:(.text+0x1ee): undefined reference to `ResultSet_getString'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::execute_query()':
query.cpp:(.text+0x28e): undefined reference to `PreparedStatement_executeQuery'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::execute()':
query.cpp:(.text+0x2e4): undefined reference to `PreparedStatement_execute'
query.cpp:(.text+0x2f3): undefined reference to `PreparedStatement_rowsChanged'
../../../lib/libmylib.a(query.cpp.o): In function `mylib::libB::query::next()':
query.cpp:(.text+0x326): undefined reference to `ResultSet_next'
collect2: error: ld returned 1 exit status
CMakeFiles/my_executable.dir/build.make:121: recipe for target 'my_executable' failed
make[2]: *** [my_executable] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/my_executable.dir/all' failed
make[1]: *** [CMakeFiles/my_executable.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
/lib/CMakeLists.txt:
cmake_minimum_required (VERSION 3.5)
project (my_executable CXX)
set (CMAKE_CXX_STANDARD 14)
set (SRC
"src/main.cpp"
"src/mysrcA.cpp"
)
set (INC
"inc/mysrcA.hpp"
)
add_library(mylib STATIC IMPORTED GLOBAL)
set_target_properties(mylib PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/../../lib/mylib.so"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/../../lib/inc"
)
add_executable (my_executable ${SRC})
target_include_directories(dbserver PRIVATE "${CMAKE_SOURCE_DIR}/inc")
target_include_directories(dbserver PRIVATE "${CMAKE_SOURCE_DIR}/../common_inc")
target_link_libraries(my_executable mylib)
/examples/my_executable/CMakeLists.txt:
cmake_minimum_required (VERSION 3.5)
project (mylib CXX)
set (CMAKE_CXX_STANDARD 14)
set (SRC
"src/mod1/mod1A.cpp"
"src/mod2/mod2A.cpp"
)
set (INC
"inc/mod1/mod1A.hpp"
"inc/mod2/mod2A.hpp"
"inc/libA/libA.hpp"
"inc/libB/libB.h"
)
add_library(mylib STATIC ${SRC} ${INC})
target_include_directories(mylib PUBLIC ${CMAKE_SOURCE_DIR}/inc)
add_library(libA STATIC IMPORTED)
set_target_properties(libA PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libA.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/inc/libA"
)
add_library(libB STATIC IMPORTED)
set_target_properties(libB PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/res/libB.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/inc/libB.h"
)
#)
target_link_libraries(mylib libA libB -lpthread)
Related
I want to add the library ixwebsocket my project. Following the instructions of the library I get the libixwebsocket.a (the compiled static library, correct me if I am wrong).
How I can use this .a file in my project?
For testing I have created the following program: main.cpp
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(cpptest VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(cpptest main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
target_link_libraries(cpptest "${CMAKE_SOURCE_DIR}/libixwebsocket.a")
//main.cpp
#include <iostream>
#include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h>
int main(int, char**) {
std::cout << "Hello, world!\n";
ix::WebSocket webSocket;
}
In the directory I have CMakeLists.txt, libixwebsocket.a and main.cpp.
I get a long list of undefined reference errors, the firsts ones:
[build] [ 50%] Linking CXX executable cpptest
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocket.cpp.o): in function `ix::WebSocket::start()':
[build] IXWebSocket.cpp:(.text+0x2240): undefined reference to `pthread_create'
ld] /usr/bin/ld: ../libixwebsocket.a(IXWebSocket.cpp.o): in function `ix::WebSocket::checkConnection(bool)':
[build] IXWebSocket.cpp:(.text+0x5b8d): undefined reference to `pthread_cond_clockwait'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) [clone .part.0]':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x67): undefined reference to `deflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateCompressor::~WebSocketPerMessageDeflateCompressor()':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x35c): undefined reference to `deflateEnd'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateCompressor::init(unsigned char, bool)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x3a6): undefined reference to `deflateInit2_'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::~WebSocketPerMessageDeflateDecompressor()':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x64c): undefined reference to `inflateEnd'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::init(unsigned char, bool)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x685): undefined reference to `inflateInit2_'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `ix::WebSocketPerMessageDeflateDecompressor::decompress(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x7d6): undefined reference to `inflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o): in function `bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> >&) [clone .part.0]':
[build] IXWebSocketPerMessageDeflateCodec.cpp:(.text+0x90d): undefined reference to `deflate'
[build] /usr/bin/ld: ../libixwebsocket.a(IXSocketOpenSSL.cpp.o): in function `ix::SocketOpenSSL::openSSLInitialize()':
[build] IXSocketOpenSSL.cpp:(.text+0x1c): undefined reference to `OPENSSL_init_ssl'
[build] /usr/bin/ld: IXSocketOpenSSL.cpp:(.text+0x29): undefined reference to `OPENSSL_init_ssl'
How may these undefined refrence errors be resolved?
Thanks in advance!
It would be always best to use find_package() calls. This way you ensure that the library is indeed installed on your system, or is exported in the build tree.
If you have the library installed on your system you can use this call, like this:
find_package(ixwebsocket REQUIRED)
target_link_libraries(cpptest ixwebsocket::ixwebsocket)
In your case, since the library is compiled independently (and it is not a target in your tree), you need to use find_library(IXWEBSOCKET_LIB ixwebsocket) and specify additional hints/names if you have the library in your own location, following the docs.
I ran into a similar issue today, the library was linking just fine but a static lib is just a collection of .o files and has no understanding of it's own dependencies...
This command worked for me:
g++ -o output/myapp -std=c++17 myapp.cpp -Llib -framework CoreFoundation -framework Security -lmylib
I'm no expert in CMake but this answer seems to indicate that the below would achieve the same effect
target_link_libraries(program "-framework CoreFoundation" "-framework Security")
So if we apply it to your case:
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(cpptest VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(cpptest main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
target_link_libraries(cpptest "${CMAKE_SOURCE_DIR}/libixwebsocket.a" "-framework CoreFoundation")
I've got a feeling pthread_create is likely to live in CoreFoundation but I'm just guessing... You may need to try a few frameworks to find the right one.
Hope this helps a little :)
We are starting to work with Zephyr and have decided to use C++. I am now trying to figure out how to unittest the code. As I understand ztest and unity which is already integrated into zephyr/nrfconnect doesn't support c++. I have decided to use googletest. I have created a custom module to download, compile and integrate into zephyr. I have now some troubles.
The structure of my project look like this:
|-modules
| |-googletest
| |-zephyr
| |-module.yml
| |-CMakeLists.txt
| |-CMakeLists.txt.in
| |-Kconfig
|-src
|-tests
|-button
| |-main.cpp
|-CMakeLists.txt
|-prj.conf
|-testcase.yaml
CMakeList of tests/button look like this:
cmake_minimum_required(VERSION 3.13.1)
set(BOARD native_posix)
set(ZEPHYR_TOOLCHAIN_VARIANT zephyr)
set(TOOLCHAIN_ROOT ${ZEPHYR_BASE})
set(ZEPHYR_EXTRA_MODULES $ENV{ZEPHYR_BASE}/../iot_aleph/modules/googletest)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project("Button unit tests")
# Include event headers
zephyr_library_include_directories(../../src/board)
# Add test sources
target_sources(app PRIVATE src/main.cpp)
target_sources(app PRIVATE ../../src/board/button.cpp)
target_link_libraries(app PUBLIC gtest_main)
CMakeLists.txt of module/googletest look like:
cmake_minimum_required(VERSION 3.1)
if(CONFIG_GOOGLETEST)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
endif()
CMakeLists.txt.in
cmake_minimum_required(VERSION 3.1)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
The GoogleTest framework seems to compile correctly but when it come to linking, I hae a lot of errors:
[92/93] Linking CXX executable zephyr/zephyr.elf
FAILED: zephyr/zephyr.elf zephyr/zephyr.lst zephyr/zephyr.stat zephyr/zephyr.exe
: && ccache /usr/bin/g++ zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj -o zephyr/zephyr.elf -Wl,-T zephyr/linker.cmd -Wl,-Map=/home/cyril/Documents/zephyr_workpsace/iot_aleph/tests/button/build/zephyr/zephyr_prebuilt.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/arch/posix/core/libarch__posix__core.a zephyr/soc/posix/inf_clock/libsoc__posix__inf_clock.a zephyr/boards/posix/native_posix/libboards__posix__native_posix.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj -L/home/cyril/Documents/zephyr_workpsace/iot_aleph/tests/button/build/zephyr lib/libgtest_main.a lib/libgtest.a -lpthread -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -lstdc++ -m32 -ldl -pthread -lm && cd /home/cyril/Documents/zephyr_workpsace/iot_aleph/tests/button/build/zephyr && cmake -E rename zephyr_prebuilt.map zephyr.map && /usr/bin/objdump -S zephyr.elf > zephyr.lst && /usr/bin/readelf -e zephyr.elf > zephyr.stat && /usr/bin/cmake -E copy zephyr.elf zephyr.exe
/usr/bin/ld: i386:x86-64 architecture of input file `lib/libgtest.a(gtest-all.cc.obj)' is incompatible with i386 output
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)':
...
gtest-all.cc:(.text+0x25bb): undefined reference to `operator new(unsigned long)'
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::AssertionResult::AssertionResult(testing::AssertionResult const&)':
gtest-all.cc:(.text+0x2876): undefined reference to `operator new(unsigned long)'
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::internal::(anonymous namespace)::SplitEscapedString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
gtest-all.cc:(.text+0x41d6): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x41f4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x4250): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x427c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::substr(unsigned long, unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x42bc): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x42f0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::substr(unsigned long, unsigned long) const'
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::internal::StringStreamToString(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)':
gtest-all.cc:(.text+0x6c0a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)'
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::Test::Test()':
gtest-all.cc:(.text+0x7b75): undefined reference to `operator new(unsigned long)'
/usr/bin/ld: lib/libgtest.a(gtest-all.cc.obj): in function `testing::TestInfo::TestInfo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, char const*, testing::internal::CodeLocation, void const*, testing::internal::TestFactoryBase*)':
gtest-all.cc:(.text+0x86b7): undefined reference to `operator new(unsigned long)'
/usr/bin/ld: gtest-all.cc:(.text+0x8726): undefined reference to `operator new(unsigned long)'
...
Can someone help me?
Cyril
Nice catch #MatzZze!
I have added:
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
And now everything is compiling and running!
I want to use GMock in my project. First of all I compiled GMock and GTest. The sequence of my actions (I use Linux):
git clone googlemock and googletest
go to GIT/googletest/googlemock/build-aux/ directory run cmake ..
and then make
As the result I got: libgmock.a and libgmock_main.a
My project has the structure: build, inc, src and lib directories. In build directory I run cmake .. and make. In inc dir I placed all headers from GIT/googletest/googlemock/include/ and GIT/googletest/googletest/include/. In lib dir lays libgmock.a only. In src - sources of my project.
My CMakeLists.txt contains:
project(blockchain)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB CPPS "*.cpp")
include_directories("../inc/")
link_directories("../lib/")
add_definitions(-Wall -O2 -std=c++11)
add_executable(${PROJECT_NAME} ${CPPS})
target_link_libraries(blockchain gmock)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
When I try to make my project (typing cmake .. && make in build dir) I get linking errors:
CMakeFiles/blockchain.dir/main.cpp.o: In function main':
main.cpp:(.text.startup+0x13): undefined reference
totesting::UnitTest::GetInstance()'
main.cpp:(.text.startup+0x1b): undefined reference to testing::UnitTest::Run()' ../lib/libgmock.a(gmock-all.cc.o): In
functiontesting::internal::scoped_ptr
::reset(std::__cxx11::basic_stringstream) [clone .part.81] [clone .constprop.367]':
gmock-all.cc:(.text+0x21a): undefined reference to testing::internal::IsTrue(bool)' ../lib/libgmock.a(gmock-all.cc.o): In
functiontesting::internal::MutexBase::AssertHeld() const [clone
.constprop.368]':
gmock-all.cc:(.text+0x274): undefined reference to testing::internal::IsTrue(bool)' gmock-all.cc:(.text+0x2b2): undefined
reference
totesting::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity,
char const, int)'
gmock-all.cc:(.text+0x2fd): undefined reference to testing::internal::GTestLog::~GTestLog()' gmock-all.cc:(.text+0x312):
undefined reference totesting::internal::GTestLog::~GTestLog()'
../lib/libgmock.a(gmock-all.cc.o): In function testing::internal::Expect(bool, char const*, int,
std::__cxx11::basic_string,
std::allocator > const&) [clone .part.51]':
gmock-all.cc:(.text+0x910): undefined reference
totesting::Message::Message()'
gmock-all.cc:(.text+0x926): undefined reference to testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type,
char const*, int, char const*)' gmock-all.cc:(.text+0x931): undefined
reference
totesting::internal::AssertHelper::operator=(testing::Message const&)
const'
gmock-all.cc:(.text+0x939): undefined reference to testing::internal::AssertHelper::~AssertHelper()'
gmock-all.cc:(.text+0x94b): undefined reference
totesting::internal::IsTrue(bool)'
And a lot of others linking errors. What am I doing wrong?
gmock depends on gtest. You added the former, but not the latter.
So, I cloned SqAtx's GitHub repository SuperMarioWorld onto my Ubuntu 16.04 (64bit) machine. I would like to run his Super Mario clone in order to understand his project and learn by the way he did this game.
First of all, I could not compile it as he explained it in the README.md. However, I have successfully compiled an own Battleship game the same way (which tells me Cmake, make, SFML, and a C compiler are correctly installed). As an error I got this error message after running cmake .. from the build folder:
CMake Error at CMakeLists.txt:24 (add_executable):
add_executable called with incorrect number of arguments
-- Found SFML 2.4.0 in /usr/include
CMake Error at CMakeLists.txt:32 (target_link_libraries):
Cannot specify link libraries for target "SuperMarioWorld" which is not
built by this project.
-- Configuring incomplete, errors occurred!
I then modified his CMakeList.txt so that it successfully creates a makefile. My CMakeList.txt looks as follows:
#Change this if you need to target a specific CMake version
cmake_minimum_required (VERSION 2.6)
# Enable debug symbols by default
# must be done before project() statement
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()
project (SuperMarioWorld)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -Wall -g")
# I guess you have not released the project yet :p
set (SuperMarioWorld_VERSION_MAJOR 0)
set (SuperMarioWorld_VERSION_MINOR 1)
set (SuperMarioWorld_VERSION_PATCH 0)
include_directories("${PROJECT_BINARY_DIR}")
set(SOURCE_FILES
EventEngine/Listeners/CharacterDiedListener.cpp
EventEngine/Listeners/CharacterPositionUpdateListener.cpp
EventEngine/Listeners/CloseRequestListener.cpp
EventEngine/Listeners/DebugInfoUpdatedListener.cpp
EventEngine/Listeners/ForegroundItemRemovedListener.cpp
EventEngine/Listeners/ForegroundItemUpdatedListener.cpp
EventEngine/Listeners/GotLevelInfoListener.cpp
EventEngine/Listeners/KeyboardListener.cpp
EventEngine/Listeners/LevelStartListener.cpp
EventEngine/Listeners/MarioJumpListener.cpp
EventEngine/Listeners/MarioKickedEnemyListener.cpp
EventEngine/Listeners/NewCharacterReadListener.cpp
EventEngine/Listeners/NewForegroundItemReadListener.cpp
EventEngine/Listeners/NewPipeReadListener.cpp
EventEngine/Listeners/ToggleIgnoreInputListener.cpp
EventEngine/EventEngine.cpp
Game/CollisionHandler.cpp
Game/GameEngine.cpp
Game/LevelImporter.cpp
Graphics/GraphicsEngine.cpp
Graphics/SpriteHandler.cpp
Sound/SoundEngine.cpp
SuperMario/Game.cpp
SuperMario/main.cpp
System/Characters/Enemy.cpp
System/Characters/Goomba.cpp
System/Characters/MovingObject.cpp
System/Characters/Player.cpp
System/Items/Box.cpp
System/Items/Pipe.cpp
System/irrXML/irrXML.cpp
System/Engine.cpp
System/Util.cpp
)
# Define sources and executable
set (EXECUTABLE_NAME "SuperMarioWorld")
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
With this CMakeList.txt I could successfully create a makefile. Running the make I first got two errors which where the same:
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/NewForegroundItemReadListener.cpp:21:95: error: taking address of temporary [-fpermissive]
m_graphicsEngine->UpdateForegroundItem(&(_event->GetDisplayableObject()->GetInfoForDisplay()));
So I had to fix it in NewPipeReadListener.cpp on line 24 and in NewForegroundItemReadListener.cpp on line 24. I fixed it like this:
InfoForDisplay temp = _event->GetPipe()->GetInfoForDisplay();
m_graphicsEngine->UpdateForegroundItem(&temp);
Now, the makefile gives me an error I cannot fix, since I don't understand a word.. I would like to include the whole error message here, but Stackoverflow doesn't allow me to do so...
But it starts like this.
[ 2%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/EventEngine/Listeners/KeyboardListener.cpp.o: In function `KeyboardListener::onEvent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Event*)':
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:12: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:13: undefined reference to `KeyboardEvent::GetKey()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:14: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:15: undefined reference to `KeyboardEvent::GetKey()'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':
I would appreciate if someone could help me understand this error and possibly make the project run on my system.
EDIT:
After fixing the the first error which was including EventEngine/KeyboardEvent.cpp it links up to a 100% and spits out the following error message:
[100%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::ReactToCollisionsWithObj(MovingObject&, DisplayableObject&, CollisionDirection)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:45: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionWithRect(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:73: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o:/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:138: more undefined references to `DisplayableObject::GetCoordinates() const' follow
CMakeFiles/SuperMarioWorld.dir/Game/GameEngine.cpp.o: In function `GameEngine::UpdateForegroundItem(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/GameEngine.cpp:114: undefined reference to `DisplayableObject::SetCoordinates(sf::Rect<float>)'
CMakeFiles/SuperMarioWorld.dir/Game/LevelImporter.cpp.o: In function `LevelImporter::StoreFloor()':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/LevelImporter.cpp:180: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::~MovingObject()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:25: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::GetInfoForDisplay()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:32: undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o:(.rodata._ZTI12MovingObject[_ZTI12MovingObject]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:3: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:8: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTV3Box[_ZTV3Box]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::~Box()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.hpp:9: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTI3Box[_ZTI3Box]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::Pipe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, int, PipeType, EventEngine*)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::~Pipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:14: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::SpawnEnemyIfTimeElapsed()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:50: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::MoveEnemyBeingSpawned(float)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:58: undefined reference to `DisplayableObject::Slide(float, float)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::IsEnemyReadyToLeavePipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:92: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x28): undefined reference to `DisplayableObject::UpdateAfterCollision(CollisionDirection, ObjectClass)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTI4Pipe[_ZTI4Pipe]+0x10): undefined reference to `typeinfo for DisplayableObject'
collect2: error: ld returned 1 exit status
CMakeFiles/SuperMarioWorld.dir/build.make:957: recipe for target 'SuperMarioWorld' failed
make[2]: *** [SuperMarioWorld] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/SuperMarioWorld.dir/all' failed
make[1]: *** [CMakeFiles/SuperMarioWorld.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
EDIT2:
Now, I feel stupid, there was another file I forgot to include, it was System/DisplayableObject.cpp.
Thanks, everyone for the help!!!
You did not include all the source files in the build.
For instance, in your error message the linker is complaining that it is missing the definition for the KeyboardEvent::GetType() function.
Searching the repo on github for KeyboardEvent will quickly tell you that this function is defined in EventEngine/KeyboardEvent.cpp, which is not part of your CMake's SOURCE_FILES.
You might be missing other source files as well. Try fixing the linker errors one by one until it compiles.
I have been trying to link OpenImageIO to an executable using CMake, but keep getting a error during the linking stage of the build. Does anyone know how to set up the CMakeLists.txt correctly so the library will link?
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")
Here is the output from running the make file...
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
You used wrong variable name to refer OpenImageIO libraries.
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(${PROJECT_NAME} ${OPENIMAGEIO_LIBRARIES})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${PROJECT_NAME} ${OPENIMAGEIO_LIBRARIES})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")