Boost tuple, linker error on Mac OS X 10.7 - macos

I have compiled boost 1.49.0 from source on a MacBook Pro running Mac OS X 10.7.3, I use Xcode 4.3.2 and Apple's LLVM 3.1 as my development environment. The following line of code (from boost http server1 example) results in a linking error as described:
void Connection::handleRead(const boost::system::error_code& error, size_t bytesTransfered) {
if (!error) {
boost::tribool result;
boost::tie(result, boost::tuples::ignore) = requestParser.parse(request, buffer.data(), buffer.data() + bytesTransfered);
if (result) {
requestHandler.handleRequest(request, reply);
async_write(socket, reply.toBuffers(), boost::bind(&Connection::handleWrite, shared_from_this(), placeholders::error));
}
else if (!result) {
reply = Reply::stockReply(Reply::badRequest);
async_write(socket, reply.toBuffers(), boost::bind(&Connection::handleWrite, shared_from_this(), placeholders::error));
}
else {
socket.async_read_some(boost::asio::buffer(buffer), boost::bind(&Connection::handleRead, shared_from_this(), placeholders::error, placeholders::bytes_transferred));
}
}
else if (error != error::operation_aborted) {
connectionManager.stop(shared_from_this());
}
}
Undefined symbols for architecture x86_64:
"boost::tuples::tuple<boost::logic::tribool, char*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> RequestParser::parse<char*>(Request&, char*, char*)", referenced from:
Connection::handleRead(boost::system::error_code const&, unsigned long) in Connection.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 searched the answers but I couldn't find anything related to it, neither I understand why the error is happening. The project links against lboost_system. Am I missing something? I am new to boost libraries.

It turns out my problem wasn't in this method, I mistakenly had RequestParser.parse() in the class implementation, checking back with the boost example the method is implemented in the declaration of the class.

Related

gcc 4.2.1 Linking issue: ATLAS 3.8.3

I'm trying to use CBLAS ATLAS. I'm a beginner. I have the following C code.
// tmp.cpp file
#include<stdio.h>
#include<stdlib.h>
#include<cblas.h>
int main(void){
float x[2] = {6,2};
float *y = (float *)malloc(2*sizeof(float));
const int n = 2;
const int incx = 1;
const int incy = 1;
float a = 5.4;
y[0] = 4.2; y[1] = 4.5;
cblas_saxpy(n,a,x,incx,y,incy);
free(y);
}
I installed the ATLAS library following the video http://youtu.be/DvLSr6zN0pU?t=6m5s and the next video "part3". However, I have no FORTRAN compiler, so I configure with
$../ATLAS/confiugre --nof77
The installation process took place as described in the video.
iMac:Desktop sotero$ ls /usr/local/atlas/include
atlas cblas.h clapack.h
iMac:Desktop sotero$ ls /usr/local/atlas/lib/
libatlas.a libcblas.a liblapack.a libptcblas.a
I tried compiling with this result
iMac:Desktop sotero$ c++ tmp.cpp
tmp.cpp:3:18: error: cblas.h: No such file or directory
tmp.cpp: In function ‘int main()’:
tmp.cpp:14: error: ‘cblas_saxpy’ was not declared in this scope
I read how to make the link to the website http://math-atlas.sourceforge.net/errata.html#LINK and I have the following to compile
iMac:Desktop sotero$ c++ tmp.cpp -L/usr/local/atlas/lib/ -lcblas -latlas -I/usr/local/atlas/include/
Undefined symbols:
"cblas_saxpy(int, float, float const*, int, float*, int)", referenced from:
_main in ccPop12J.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I do not know how I should compile. I just need to level one BLAS. I've been looking to compile if you do link to the ATLAS library, but I'm lost.
How I can fix it?

OpenSSL and Rand_bytes

My question is in regards to using OpenSSL on Mac via GCC.
#include <stdio.h>
#include <openssl/rand.h>
int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}
I have the following code, that I am trying to compile with GCC. Here is what I enter into the command line
gcc -o ossl ossl.c -lcrypto -lssl
However I get the following error.
Undefined symbols for architecture x86_64:
"_Rand_bytes", referenced from:
_main in cc2hf0Ij.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I am not experienced when it comes to using openssl. Why am I receiving Undefined symbols for architecture x86_64?
int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}
Try RAND_bytes:
int main()
{
unsigned char key[128];
int rc = RAND_bytes(key,sizeof(key));
if(rc != 1)
/* Handle failure */
...
OPENSSL_cleanse(key,sizeof(key));
return 0;
}
The OpenSSL docs are at RAND_bytes(3).

CppUTest example doesn't work

I just installed CppUTest on my MAC using brew as indicated by the guide.
It failed when I tried to build the example cpp.
TEST_GROUP(FirstTestGroup)
{
};
TEST(FirstTestGroup, FirstTest)
{
FAIL("Fail me!");
}
I guess it is because the header file which define those macros are not included. So I add include as below:
#include "CppUTest/TestHarness.h"
#include "CppUTest/TestOutput.h"
TEST_GROUP(FirstTestGroup)
{
};
TEST(FirstTestGroup, FirstTest)
{
FAIL("Fail me!");
}
Now I get bunch of errors.
Undefined symbols for architecture x86_64: "UtestShell::assertTrue(bool, char const*, char const*, char const*, int)", referenced from: vtable for TEST_FirstTestGroup_FirstTest_TestShellin ccNDwnbv.o
The error you are getting is a linker error and it suggests that you are not linking the CppUTest library. It is hard to actually say what is wrong because your question is missing the Makefiles. Could you explain how you have compiled the example?

matlab mex clang C++11 thread -> Undefined symbols error

Goal: I want to use thread STL of C++11 in Matlab mex file (R2013a) using Xcode 4.6
I modified ~/.matlab/R2013a/mexopts.sh
CC='clang++' # was llvm-gcc-4.2
CXX='clang++' # was llvm-g++-4.2
MACOSX_DEPLOYMENT_TARGET='10.8' # was 10.5. C++11 is supported >=10.7
CXXFLAGS="$CXXFLAGS -std=gnu++11 -stdlib=libc++" # additional flags
Normal mex files without C++11 features are compiled well. Further, STL is well detected by the compiler except linking failure.
>> mex mextest.cpp
Undefined symbols for architecture x86_64:
"std::__1::__thread_struct::__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__thread_struct::~__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__thread_local_data()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<void (*)()> >(void*) in mextest.o
"std::__1::__throw_system_error(int, char const*)", referenced from:
_mexFunction in mextest.o
"std::__1::thread::join()", referenced from:
_mexFunction in mextest.o
"std::__1::thread::~thread()", referenced from:
_mexFunction in mextest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "mextest.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
The actual source code is shown below. The details are not important because it compiles well in Matlab R2013 WINDOWS version with Visual Studio 2012 Express. An equivalent cpp was also well compiled with "clang++ -std=gnu++11 -stdlib=libc++ clangtest.cpp". So, at least, there is no logical error in the codes (I'm not saying it is safe codes. It is just a test.)
#include "mex.h"
#include <thread>
#include <stdio.h>
int count_thread1 = 0;
int count_thread2 = 0;
void hello()
{
count_thread2 = 0;
for(int i=0; i<=10000; i++){
for (int j=1;j<=20000;j++){
count_thread2 = i-j-1;
}
count_thread2++;
printf("2: %d , %d\n", count_thread1, count_thread2); // Not sure if printf is thread-safe in Matlab. But it works in this particular example
}
}
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
count_thread1 = 0;
std::thread t(hello);
for (int i=1;i<=10000;i++)
{
for (int j=1;j<=20000;j++){
count_thread1 = -i+j-1;
}
count_thread1++;
mexPrintf("1: %d , %d\n", count_thread1, count_thread2);
}
mexPrintf("\n");
t.join();
mexPrintf("Done\n");
}
It seems like I have to replace some include directories and/or library directories. What kind of options should be modify?
Thank you.
The error is due to compiling against -stdlib=libc++ but linking against -lstdc++. You can fix it in one of two ways:
Fix it in mexopts.sh. The most drastic and effective solution. Located in ~/.matlab/${MATLAB_VERSION}/mexopts.sh, this determines all compiler options. Simply find/replace all stdc++ to c++.
Patchwork solution: Simply add -lc++ to the tail end of CXXLIBS. I'm not sure what the effect of linking against multiple versions of the standard libraries is, but it seems to work. In your mex invocation, add the argument CXXLIBS="\$CXXLIBS -lc++".
As a secondary issue, I believe you're completely overwriting the value of CXXFLAGS; you must escape the $ symbol as I did above with the libraries.

Xcode 'Undefined symbols for architecture x86_64:' error?

Error: " Undefined symbols for architecture x86_64:
"f(int, int, int const (*) [8], int const (*) [8], int*, int*)", referenced from:
_main in main.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 tried running the exact same code on Visual Studio 2010, and it worked! Any idea why it doesn't work here? My Mac is 64bit. Thanks!
Here's the code on the files that's giving the error:
#include <iostream>
using namespace std;
int p,q;
int f( int, int,const int [][8],const int [][8], int [],int []);
This happens if you haven't provided an implementation of your f(..) function.
In your main.cpp file, simply implement the function, like:
int f( int, int,const int [][8],const int [][8], int [],int [])
{
// Do stuff...
}

Resources