3

I have a cpp file that compiles fine with g++ by using the shell:

extern "C"{
  #include <quadmath.h>
}

inline char* print( const __float128& val)
{
  char* buffer = new char[128];
  quadmath_snprintf(buffer,128,"%+.34Qe", val);
  return buffer;
}
int main(){
    __float128 a = 1.0;
    print(a);
    return 0;
}

However, when I try to compile it via a python scrit, it fails with the following error:

"undefined reference to quadmath_snprintf"

Here the code of the python script:

import commands
import string
import os
(status, output) = commands.getstatusoutput("(g++ test/*.c -O3 -lquadmath -m64)")

Any idea how to solve this? Thanks.

1
  • 1
    Probably you don't have LIBRARY_PATH correctly set from python. Try use -L on g++ or export LIBRARY_PATH first. Commented Oct 5, 2016 at 8:05

1 Answer 1

3

When you open a shell a whole of stuff is silently initialized for you, and most important for your issue, environment variables are set. What you most likely miss is the definition of LIBRARY_PATH, which is the variable used by the linker to look for libraries matching the ones you instruct it to link using the -lNAME flags.

What the linker needs is a list of directories where it will search for files matching libNAME.{a,so}. You can also pass these directories directly using the -L flag, but in general, you should probably try to use a program like CMake, Make or any other build tool.

This will give you access to commands like find_package and target_link_libraries (CMake), to find, respectively add libraries to your build targets, instead of having to maintain your python to compile your stuff.

Sign up to request clarification or add additional context in comments.

2 Comments

-L option is looking for LIBRARY_PATH, not LD_LIBRARY_PATH (that's for runtime). Fix your answer please.
I made the same mistake! ;) +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.