Attempting to use Boost.Filesystem however it doesn't seem to link? - c++

I'm using OS X 10.7.3. I've been playing with the boost headers for a while now and i wanted to move onto using the Boost.Filesystem lib however it keeps throwing this message at me:
Undefined symbols for architecture x86_64:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
boost::filesystem3::detail::create_directories(boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::canonical(boost::filesystem3::path const&, boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
(anonymous namespace)::error(bool, boost::system::error_code const&, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
(anonymous namespace)::error(bool, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
(anonymous namespace)::error(bool, boost::filesystem3::path const&, boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::dir_itr_close(void*&, void*&)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_itera tor&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_itera tor&, boost::filesystem3::path const&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
i get this when i try to compile using this:
g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_filesystem.a
So i went back to the boost.org tutorials and tried out the regex example. It worked perfectly using this:
g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_regex.a

try
g++ -o test main.cpp -I/opt/local/include -L/opt/local/lib -lboost_filesystem

Your compiler flags seem a bit off. Generally, the following hold:
-I // Sets the path for the relevant header files
-L // Sets the path where your libraries reside
-l // specifies the library you want to link against.
So, if you have a library called mylib in ~/libs/ and need to use header files located in ~/include, you'd pass
-I ~/include -L ~/libs -lmylib
as flags to the compiler.

Related

Installing gRPC : ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'

OS -> OSX El Captain Version 10.11.6
Tried to install gRPC using the below commands:
git clone-b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
cd grpc
git submodule update --init
make
I got the below error:
[HOSTCXX] Compiling src/compiler/cpp_plugin.cc
[HOSTLD] Linking /<path>/grpc/bins/opt/grpc_cpp_plugin
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
Undefined symbols for architecture x86_64:
"google::protobuf::io::StringOutputStream::StringOutputStream(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >*)", referenced from:
ProtoBufFile::CreatePrinter(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >*) const in cpp_plugin.o
"google::protobuf::io::Printer::Print(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, char const*)", referenced from:
ProtoBufPrinter::Print(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, char const*) in cpp_plugin.o
"google::protobuf::FileDescriptor::GetSourceLocation(std::__1::vector<int, std::__1::allocator<int> > const&, google::protobuf::SourceLocation*) const", referenced from:
void grpc_generator::GetComment<google::protobuf::FileDescriptor>(google::protobuf::FileDescriptor const*, grpc_generator::CommentType, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*) in cpp_plugin.o
"google::protobuf::compiler::CodeGenerator::GenerateAll(std::__1::vector<google::protobuf::FileDescriptor const*, std::__1::allocator<google::protobuf::FileDescriptor const*> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, google::protobuf::compiler::GeneratorContext*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const", referenced from:
vtable for CppGrpcGenerator in cpp_plugin.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: *** [/<path>/grpc/bins/opt/grpc_cpp_plugin] Error 1
This is what I have in
/<path>/grpc/libs/opt/ directory :
- libares.a
- libgpr.a
- libgrpc_cronet.a
- libgrpc_unsecure.a
- libboringssl.a
- libgrpc.a
- libgrpc_plugin_support.a
- pkgconfig
[EDIT]
After uninstalling protobuf and running make again I get the below warnings :
[LD] Linking /<path>/grpc/libs/opt/libgpr.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc_cronet.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc_unsecure.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc++.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc++_cronet.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc++_error_details.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc++_reflection.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
[LD] Linking /<path>/grpc/libs/opt/libgrpc++_unsecure.dylib
ld: warning: directory not found for option '-L/<path>/grpc/libs/opt/c-ares'
If I proceed with the installation by executing 'sudo make install', protobuf doesn't get installed and grpc_cpp_plugin doesn't work (gives the below error).
grpc_cpp_plugin: program not found or is not executable
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.
[EDIT]
For the c-ares problem, i installed it using homebrew brew install c-ares. Then installed grpc grpc-1.3.0.tar.gz and protobuf libprotoc 3.2.0 without errors. But when i run make in the helloworld example, i'm getting the below error :
protoc -I ../../protos --cpp_out=. ../../protos/helloworld.proto
g++ -std=c++11 -I/usr/local/include -pthread -c -o helloworld.pb.o helloworld.pb.cc
protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/helloworld.proto
g++ -std=c++11 -I/usr/local/include -pthread -c -o helloworld.grpc.pb.o helloworld.grpc.pb.cc
g++ -std=c++11 -I/usr/local/include -pthread -c -o greeter_client.o greeter_client.cc
g++ helloworld.pb.o helloworld.grpc.pb.o greeter_client.o -L/usr/local/lib `pkg-config --libs grpc++ grpc` -lgrpc++_reflection -lprotobuf -lpthread -ldl -o greeter_client
Undefined symbols for architecture x86_64:
"grpc::CreateChannel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<grpc::ChannelCredentials> const&)", referenced from:
_main in greeter_client.o
"google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))", referenced from:
helloworld::protobuf_helloworld_2eproto::AddDescriptorsImpl() in helloworld.pb.o
"google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)", referenced from:
google::protobuf::internal::WireFormatLite::WriteStringToArray(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*) in helloworld.pb.o
"google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)", referenced from:
helloworld::HelloRequest::HelloRequest(helloworld::HelloRequest const&) in helloworld.pb.o
helloworld::HelloRequest::HelloRequest(helloworld::HelloRequest const&) in helloworld.pb.o
helloworld::HelloRequest::MergeFrom(helloworld::HelloRequest const&) in helloworld.pb.o
helloworld::HelloReply::HelloReply(helloworld::HelloReply const&) in helloworld.pb.o
helloworld::HelloReply::HelloReply(helloworld::HelloReply const&) in helloworld.pb.o
helloworld::HelloReply::MergeFrom(helloworld::HelloReply const&) in helloworld.pb.o
"google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)", referenced from:
helloworld::HelloRequest::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const in helloworld.pb.o
helloworld::HelloReply::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const in helloworld.pb.o
"google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) in helloworld.pb.o
"google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)", referenced from:
helloworld::protobuf_helloworld_2eproto::(anonymous namespace)::protobuf_AssignDescriptors() in helloworld.pb.o
"google::protobuf::internal::fixed_address_empty_string[abi:cxx11]", referenced from:
google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]() in helloworld.pb.o
google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]() in greeter_client.o
"google::protobuf::Message::GetTypeName[abi:cxx11]() const", referenced from:
vtable for helloworld::HelloReply in helloworld.pb.o
vtable for helloworld::HelloRequest in helloworld.pb.o
"google::protobuf::Message::InitializationErrorString[abi:cxx11]() const", referenced from:
vtable for helloworld::HelloReply in helloworld.pb.o
vtable for helloworld::HelloRequest in helloworld.pb.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [greeter_client] Error 1
Thanks
It could be related with wrong or corrupted version of installed ProtoBuf, because if protobuf is installed and has version more than 3.0, than gRPC building system uses system's protobuf, instread thrird-party-protobuf from subrepo. Try to remove or fix protobuf in your system.
UPDATE:
For new issues try to run "readelf -s lib???.so" for each grpc and protobuf library, and try to find this symbols in libraries. If in some library is specified "UND", than it is wrong library.
Second things that you should do, run "file lib???.so" for each grpc and protobuf library for check binary type: x86_64 or not.

Protobuffer 2.6 Linking Error with gcc 4.8 (macports)

I have version 2.6 of Google protobuffers installed via macports and gcc 4.8 and, when I compile my code (with the -lprotobuf flag), get the following link error:
Undefined symbols for architecture x86_64:
"google::protobuf::MessageLite::ParseFromString(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in cclSIxVT.o
"google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))", referenced from:
protomessages::protobuf_AddDesc_msg_2eproto() in cc219IO6.o
"google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)", referenced from:
protomessages::DatabaseRequestInfo::SerializeWithCachedSizesToArray(unsigned char*) const in cc219IO6.o
"google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)", referenced from:
protomessages::DatabaseRequestInfo::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const in cc219IO6.o
"google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
protomessages::DatabaseRequestInfo::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) in cc219IO6.o
"google::protobuf::DescriptorPool::FindFileByName(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const", referenced from:
protomessages::protobuf_AssignDesc_msg_2eproto() in cc219IO6.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
My LD_LIBRARY_PATH is correct (otherwise the -lprotobuf flag would not be recognised)
protoc --version returns 2.6.1
I am also compiling with the generated pb.o files so I don't think this is related to , what i know is a common omission.
The command in question I'm using is :
g++ -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-long-long -Wno-variadic-macros -Wno-deprecated -Wno-unused-function -Wno-vla -Wno-unused-variable -std=c++11 -o testbin util/myutil.o util/config.o util/MySemaphore.o network/jobMsg.o network/JobQueue.o network/Message.o network/protocolMsgs.o network/socket/receiver.o network/socket/sender.o blocks/Block.o cluster.o blocks/tc/MVTxCoord.o blocks/tc/StoredProcedure.o blocks/tc/TxCoord.o blocks/tc/IInGroupTC.o blocks/tc/InGroupTCFactory.o blocks/tc/DummyInGroupTC.o blocks/tc/2PLInGroupTC.o blocks/ds/DataService.o blocks/ds/MVDataService.o blocks/ds/HashTableIndex.o blocks/ds/Storage.o blocks/ds/IInGroupDS.o blocks/ds/InGroupDSFactory.o blocks/ds/DummyInGroupDS.o blocks/ds/2PLInGroupDS.o blocks/ds/Lock.o blocks/gm/GroupManager.o blocks/ts/TimestampServer.o blocks/client/Client.o blocks/client/ClientLib.o blocks/client/ClientEnv.o msg.pb.o microbenchmarks/main.o -L/opt/local/lib -lprotobuf -lpthread
I've checked that the library is compiled for 64 bits.
Non-fat file: /opt/local/lib/libprotobuf.a is architecture: x86_64
Any ideas where I am going wrong?

OpenCV, Undefined symbols for architecture x86_64 error

I'm trying to get OpenCV to work on my computer - for simple programs I can get it to work but for this certain program I'm unable to. The error I am getting is as follow:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccuX28GE.o
"cv::split(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >&)", referenced from:
computeFocusDPC(std::vector<R_image, std::allocator<R_image> >, int, float, int, int, int, int, cv::Mat*) in ccuX28GE.o
qDPC_loop(std::vector<cv::Mat, std::allocator<cv::Mat> >, std::vector<cv::Mat, std::allocator<cv::Mat> >, double) in ccuX28GE.o
"cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccuX28GE.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in ccuX28GE.o
ld: symbol(s) not found for architecture x86_64
I'm trying to compile the file with the command line
g++-5.1.0 -o qDPC_desktop qDPC.cpp -I. -std=c++11 -ggdb -fopenmp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching
I know that this error is not in the code of qDPC.cpp since it can compile on my friend's Ubuntu (I'm working on a Mac) - so I was wondering if there's something wrong with my OpenCV? I've read online online that it might be a linker problem but can't for the life of me figure this problem out. The version of OpenCV I have is 2.4.11, and the version my friend is able to compile with is 2.4.9.
All help is appreciated!

C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1

After upgrading to Mac OS X 10.9 / Xcode 5.0.1, command lines to create a shared library (.dylib) failed with several undefined symbols.
clang++ -dynamiclib -install_name test.dylib *.o -o test.dylib
Undefined symbols for architecture x86_64:
"std::allocator<char>::allocator()", referenced from:
_main in test.o
"std::allocator<char>::~allocator()", referenced from:
_main in test.o
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in test.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in test.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in test.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test.o
"std::cout", referenced from:
_main in test.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in test.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in test.o
ld: symbol(s) not found for architecture x86_64
The answer is there: https://mathematica.stackexchange.com/questions/34692/mathlink-linking-error-after-os-x-10-9-mavericks-upgrade
There are two implementations of the standard C++ library available on OS X: libstdc++ and libc++. They are not binary compatible and libMLi3 requires libstdc++.
On 10.8 and earlier libstdc++ is chosen by default, on 10.9 libc++ is chosen by default. To ensure compatibility with libMLi3, we need to choose libstdc++ manually.
To do this, add -stdlib=libstdc++ to the linking command.
Related post: Compiling with Clang using Libc++ undefined references
Edit: After some investigations it seems there is a link between the -mmacosx-version-min and the choice of the default libstd. If min version < 10.9, then the default libstd is equal to libstdc++, else to libc++. The long term solution is clearly to use -stdlib=libc++
Those suggestions did not work for me with Mac El capitan. If you have similar issues after upgrading to El Capitan, just run
xcode-select --install
before trying to compile

C++ Undefined Symbol error in OSX10.7.4

The following call from the command line, clang++ vcfaltcount.cpp -o vcfac, produces the following error/warnings
>In file included from vcfaltcount.cpp:1:
./Variant.h:86:5: warning: control may reach end of non-void function [-Wreturn-type]
}
>Undefined symbols for architecture x86_64:
"split(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in ccGOdUhH.o
vcf::VariantCallFile::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
"vcf::VariantCallFile::getNextVariant(vcf::Variant&)", referenced from:
_main in ccGOdUhH.o
"vcf::VariantCallFile::parseHeader()", referenced from:
vcf::VariantCallFile::openFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccGOdUhH.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
There are many other posts on "undefined symbols for such&such architecture," and I have attempted to use those suggestions to successfully compile.
I think the problem may arise from the header file, variant.h. In the API from which the source code came there was a corresponding variant.cpp file that defined the functions, which were only declared in variant.h. I moved those definitions into variant.h. Any thoughts on what I may be missing? I can provide the header if need be, but it is long. Thanks.