I tried different ways to run the hello world example from the openvdb cookbook for the latest version 5.1.0. But I keep on getting Undefined symbols for architecture x86_64
error on my MacBook pro (macOS High Sierra 10.13.4).
To narrow down the problem, I simplify the hello world example as:
//test.cpp
#include <openvdb/openvdb.h>
#include <iostream>
int main()
{
openvdb::initialize();
}
To compile the code, I installed openvdb 5.1.0 using homebrew brew install openvdb
. The command line I use to compile the code is (g++ version = 5.4.0):
g++ -g -std=c++11 -I/usr/local/Cellar/openvdb/5.1.0_1/include \
-I /usr/local/Cellar/boost/1.67.0_1/include \
-I /usr/local/Cellar/tbb/2018_U4/include \
-L /usr/local/Cellar/openvdb/5.1.0_1/lib \
-L /usr/local/Cellar/boost/1.67.0_1/lib \
-L /usr/local/Cellar/tbb/2018_U4/lib \
test.cpp -lopenvdb -ltbb -lHalf -lpthread
What I got is:
Undefined symbols for architecture x86_64:
"openvdb::v5_1::math::simplify(std::shared_ptr<openvdb::v5_1::math::AffineMap>)", referenced from:
openvdb::v5_1::math::AffineMap::preRotate(double, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::AffineMap::preShear(double, openvdb::v5_1::math::Axis, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::AffineMap::postRotate(double, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::AffineMap::postShear(double, openvdb::v5_1::math::Axis, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::ScaleMap::preRotate(double, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::ScaleMap::preShear(double, openvdb::v5_1::math::Axis, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
openvdb::v5_1::math::ScaleMap::postRotate(double, openvdb::v5_1::math::Axis) const in ccBVTtHl.o
...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
It seems the openvdb
lib does not have the function implementation included. Did I miss something?
I also tried to compile from openvdb git v5.1.0.Other dependent packages are installed via homebrew (Only blosc is pulled from c-blosc git). However, the error is the same.
Anyone experience the same issue to make openvdb 5.1.0 run on Mac?
Update:
I try to use nm
to figure out if the symbol inside test.o (use the same compile command without referring to any library) is inside openvdb.dylib
. My target symbol here is simplify
. The output is as below:
$ nm -A test.o | grep simplify
test.o: U __ZN7openvdb4v5_14math8simplifyESt10shared_ptrINS1_9AffineMapEE
$ nm -A libopenvdb.dylib | grep simplify
libopenvdb.dylib: 0000000000027a2a T __ZN7openvdb4v5_14math8simplifyENSt3__110shared_ptrINS1_9AffineMapEEE
$ nm -A git5.1.0/libopenvdb.dylib | grep simplify
libopenvdb.dylib: 00000000000d56c0 T __ZN7openvdb8v5_1abi34math8simplifyEN5boost10shared_ptrINS1_9AffineMapEEE
(I removed the path for better readability)
This is it! I have highlighted the three difference. I do not know the exact meaning of the highlighted part. My guess is that the shared_ptr in three file comes from different sources (C++x0,C++11,Boost)? But I compile test.o with Boost header included and c++11 turned on.
Any good suggestion for reasoning the difference?