1

I need to write a python wrapper for an existing C++ Module. First I tested the procedere with this basic example (which now actually works fine): C++ - Python Binding with ctypes - Return multiple values in function

Now I tried to change the setting: I want to use the existing lib instead of my single cpp file. I tried it with this:

g++ -c -I. -fPIC projectionWrapper.cpp -o projectionWrapper.o
g++ -shared -Wl,-soname,libproj.so 
    -L./build/liborig_interface.a,./build/liborig_base.a 
    -o libproj.so  projectionWrapper.o 

I wanted to link against both .a files from the given library with the -L command. I don't get any errors on that, but when I try to import the module via ipython, I get this:

import myprojection    # I load libproj.so in this python file
OSError: ./libproj.so: undefined symbol: _Z29calibration_loadPKcjbP14camera_typetS2_

There is a function "calibration_load", as well a "camera_type" in the original framework. But I have no clue where the cryptic things in between come from.

Sorry for my vague explanation, I tried to explain it as good as possible, but a C++ Wrapper is not one of my topics where I feel "at home".

2 Answers 2

1

The problem is that you're not linking against the external library that you use in your C++ code; add -l<library> to your second g++ call.

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

Comments

0
g++ -shared projectionWrapper.o 
    -L./build/base -L./build/interface
    -loriginterface -lorigbase 
    -Wl,-soname,libproj.so  
    -o libproj.so

did the job. Thanks for the hint that I actually didn't link the libraries as I only used the -L option.

Moreover the order of the options was wrong. I had to state "projectionWrapper.o" right at the beginning, as well as "-loriginterface" before "-lorigbase". This was answered here: "undefined reference" when linking against a static library

(complete name of the libs are: liboriginterface.a and liborigbase.a)

Comments

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.