GMP library 6.0.0 doesn't compile on Mac OS Mavericks - c++

I am trying to compile this example program
#include <iostream>
#include <gmpxx.h>
int main(int argc, const char * argv[])
{
mpz_class rho = 3;
std:cout << rho;
return 0;
}
and I get this error:
Undefined symbols for architecture x86_64:
"___gmpz_clear", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() in main-5858d5.o
"___gmpz_init_set_si", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) in main-5858d5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I compile my main manually with this command:
clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx main.cpp
GMP has been installed through MacPorts:
$port list gmp
gmp #6.0.0 devel/gmp
Compiler's info:
$clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
some more info:
ll /opt/local/lib/libgmp*
/opt/local/lib/libgmp.10.dylib
/opt/local/lib/libgmp.a
/opt/local/lib/libgmp.dylib -> libgmp.10.dylib
/opt/local/lib/libgmpxx.4.dylib
/opt/local/lib/libgmpxx.a
/opt/local/lib/libgmpxx.dylib -> libgmpxx.4.dylib
and:
ll /opt/local/include/gmp*
/opt/local/include/gmp.h
/opt/local/include/gmpxx.h

Running clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx -lgmp main.cpp made the trick thanks #n.m.

Related

libuvc program does not compile

I'm trying to use libuvc in one of my C/C++ projects. I succesfully compiled and installed both libusb and libuvc from source and when I attempt to compile the following code using gcc:
#include "libuvc/libuvc.h"
int main (int argc, const char **argv) {
uvc_init(NULL, NULL);
}
I get the following error:
Undefined symbols for architecture x86_64:
"_uvc_init", referenced from:
_main in main-de2855.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm on MacOS High Sierra 10.13.1 x64.
I used the command:
gcc main.c -luvc -o main
and it worked! Adding the -luvc flag solved my problem, but I don't understand why I need to use it. I've never needed flags before when working with other C/C++ dependencies.

ACE fails at Linker in MAC OS X 10.9 (and higher)

I am trying to compile and run the following simple code in MAC OS X 10.9 with CLANG++:
#include "ACE_wrappers/ace/MEM_Stream.h"
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
ACE_MEM_Stream m(3);
m.close_reader();
return 0;
}
But I get the following error:
QAs-MacBook:aceTestLinking Moamen$ clang++ myTest.cpp
Undefined symbols for architecture x86_64:
"ace_os_main_i(int, char**)", referenced from:
_main in moamen-511a28.o
"ACE_SOCK::ACE_SOCK()", referenced from:
ACE_MEM_IO::ACE_MEM_IO() in moamen-511a28.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The compile line:
clang++ myTest.cpp
The CLANG Compiler version I am using:
QAs-MacBook:aceTestLinking Moamen$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
Notice - I have also tried to compile with "-std=c++11", "-stdlib=libstdc++", as in the following topic:
C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1
but did not solve the issue.
Thanks,
Moamen
Thanks for the replies, after some investigation on Linux Ubuntu, I succeeded to compile the code with the following command g++ -o m.out myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/ -lpthread -ldl. Seems some default libs were missing!

GDAL API in C/C++

I'm trying to compile the following program (using GDAL API in C++):
main.cpp:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char *argv[])
{
GDALAllRegister();
GDALDataset* data = (GDALDataset*) GDALOpen( "heightmap.tiff", GA_ReadOnly );
}
the way I build it on a Mac :
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include
and got this:
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include/
Undefined symbols for architecture x86_64:
"_GDALOpenShared", referenced from:
_main in test_gdal-QIB6MK.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What's wrong with this very basic case?
Try to build your project on a Mac using bash file:
#!/usr/bin/env bash
## Path to you installed GDAL
GDAL_PATH=/usr/local/Cellar/gdal2/2.2.0
INCLUDE_PATH=${GDAL_PATH}/include
LIBS_PATH=${GDAL_PATH}/lib
GDAL_LIB=-lgdal
g++ -I${INCLUDE_PATH} -L${LIBS_PATH} ${GDAL_LIB} main.cpp -o main

Link error with boost::archive::test_oarchive using gcc OS X

I'm building a project that requires boost's text_oarchive function, and am getting a linker error when trying to build it.
I've installed Boost 1.55.0 on OS X 10.9
My compiler information is reported as:
$g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
The bootstrap.log file in the boost directory reports the "'darwin' toolset" was used.
however, when building from Eclipse, the following error is reported at the end of the build output:
"boost::archive::detail::basic_oarchive::~basic_oarchive()", referenced from:
::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive() in msgQueProducer.o
"typeinfo for boost::archive::archive_exception", referenced from:
void boost::serialization::throw_exception<boost::archive::archive_exception> (boost::archive::archive_exception const&) in msgQueProducer.o
"typeinfo for boost::archive::detail::basic_oarchive", referenced from:
typeinfo for boost::archive::detail::common_oarchive<boost::archive::text_oarchive> in msgQueProducer.o
"vtable for boost::archive::archive_exception", referenced from:
boost::archive::archive_exception::archive_exception(boost::archive::archive_exception const&) in msgQueProducer.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [msgQueProducer] Error 1
The project builds fine when the following single line of code removed from the project:
boost::archive::text_oarchive oa(oss);
I'm wondering if when I built the boost libraries I should have specified some architecture parameters (passing to the ./b2 tool something like "./b2 toolset=darwin cxxflags="-arch i386" address-model=64 architecture=x86 stage"). However, I'm building with another boost function used for interprocess messaging, and the project builds fine with it included.
The boost project includes I'm using are:
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/archive/text_oarchive.hpp>
What do I need to do to use boost::text_oarchive on my OS X system?
Thanks in advance,
Walt
You need to link the boost-serialization library. Add -lboost_serialization to your LDFLAGS.

Compile and use boost 1.51.0 on Mac OS X 10.8

So I've spent the last 20 hours trying to get boost working under OS X 10.8, and I have finally gotten it to compile without errors, but when I try to compile a test case that uses Boost.test, I'm back again in a world of hurt.
I should mention, the reason I compile boost myself instead of using the binary available, is because I want to use c++11 and libc++.
When I compiled boost, I called b2 like this:
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-std=c++11 -stdlib=libc++" link=static
and it compiles all file. Then I have this piece of code
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Addition
#include <boost/test/unit_test.hpp>
int addition(int i, int j)
{
return i + j;
}
BOOST_AUTO_TEST_CASE(universeInOrder)
{
BOOST_CHECK(addition(2, 2) == 4);
}
which I
try to compile with
clang++ -std=c++11 -stdlib=libc++ -g -Wall -v -I/Users/cb/Downloads/boost_1_51_0 tests/arithmetic.cpp -o tests/arithmetic /Users/cb/Downloads/boost_1_51_0/stage/lib/libboost_unit_test_framework.a`
And it fails miserably, giving me this error:
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o tests/arithmetic /var/folders/pg/4wcxn1j12c3188vqrv0x4w9r0000gn/T/arithmetic-UFmO1B.o /Users/cb/Downloads/boost_1_51_0/stage/lib/libboost_unit_test_framework.a -lc++ -lSystem /usr/bin/../lib/clang/4.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::unit_test::unit_test_main(bool (*)(), int, char**)", referenced from:
_main in arithmetic-UFmO1B.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At first, I figured it was because boost was not compiled for 64bit so I tried telling b2 to do that specifically, but it made no difference, and I also think that it compiles for 64bit by default on OS X.
Any ideas as to why it is failing and how I get it working?
It looks like bad compilation of the test. You requested
#define BOOST_TEST_DYN_LINK
but than you are linking the static version of boost.test
/Users/cb/Downloads/boost_1_51_0/stage/lib/libboost_unit_test_framework.a
and IIRC there is a difference between the static and dynamic versions of this library. So either link the dynamic version of the library (the one with .so extension), or remove that define.