简体   繁体   中英

How can I cmake/make a CGAL binary that correctly links against a libassimp dylib on OSX?

I think this is very simple for someone who knows about this stuff; please over-explain because I'm not used to cmake or command line development on OSX.

I am getting started with CGAL and have one of the examples correctly buildings and running from Terminal ( http://doc.cgal.org/latest/AABB_tree/ section 3.2). I copy that code to a .cpp in its own folder, and then

/opt/local/bin/cgal_create_cmake_script
cmake .
make .

This works fine; the cgal create script bootstraps a cmake file, and then its a standard build process from there.

I am now interested in using libassimp to add to that example project, in order to load .PLY files. In a different folder I acquired the source for libassimp, and installed via:

cmake -G 'Unix Makefiles'
make
sudo make install

This appears successful; several libassimp .h files are in /usr/local/lib/libassimp, as well as a /usr/local/lib/libassimp.dylib

Back in my CGAL example project, I try

#include <assimp/Importer.hpp>

int main() {
    Assimp::Importer importer;
    return 0;
}

(ie just to test successful integration of the library.)

When I run make I get:

[100%] Building CXX object CMakeFiles/sample.dir/sample.cpp.o
Linking CXX executable sample
Undefined symbols for architecture x86_64:
  "Assimp::Importer::Importer()", referenced from:
      assimp_test() in sample.cpp.o
      _main in sample.cpp.o
  "Assimp::Importer::~Importer()", referenced from:
      assimp_test() in sample.cpp.o
      _main in sample.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [sample] Error 1
make[1]: *** [CMakeFiles/sample.dir/all] Error 2
make: *** [all] Error 2

This does not surprise me; I presumably need to add something to CMakelists.txt. But what!

Found this after asking, which gave me the clues I needed: How to find a library with cmake?

Essentially I changed the relevant lines in my CMakelists.txt to read:

  create_single_source_cgal_program( "sample.cpp" )

  target_link_libraries (sample assimp)

this works because apparently when you tell cmake to target_link_libraries(EXENAME FOO), it will look for /usr/local/lib/libFOO.dylib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM