linking C++ programs to Python - c++

For linking C++ and python I used the following commands:
Compiling the actual function:
g++ -c -fpic main.cpp
Generate the wrapping C code using SWIG:
swig -c++ -python main.i
Compile the wrapping C code:
g++ -c -fpic main_wrap.cxx -I/usr/include/python2.7
for Linking everything together I used these tow instruction:
1) g++ -shared main.o main_wrap.o -o _main.so
2) g++ -lpython -shared main.o main_wrap.o -o _main.so
and got errors in both but less in the second one. (for the func.c example I checked and it only be linked with -lpython flag be set!)
however, it still gives me following errors:
Undefined symbols for architecture x86_64:
"std::vector<double, std::allocator<double> > power_method<double>(double, int)", referenced from:
__wrap_power_methodDouble in main_wrap.o
"std::vector<float, std::allocator<float> > power_method<float>(float, int)", referenced from:
__wrap_power_methodFloat in main_wrap.o
"std::vector<int, std::allocator<int> > power_method<int>(int, int)", referenced from:
__wrap_power_methodInt in main_wrap.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Show message history

Related

cpp - make with lboost_system - how to make it work

In my cpp project, I have header file with #include <boost/asio.hpp>.
i also got a makefile attached to the project:
CFLAGS:=-c -Wall -Weffc++ -g -std=c++11 -Iinclude
LDFLAGS:=-L/Users/user/Downloads/boost_1_61_0
all: EchoClient
g++ -o bin/echoExample bin/connectionHandler.o bin/echoClient.o $(LDFLAGS)
EchoClient: bin/connectionHandler.o bin/echoClient.o
bin/connectionHandler.o: src/connectionHandler.cpp
g++ $(CFLAGS) -o bin/connectionHandler.o src/connectionHandler.cpp
bin/echoClient.o: src/echoClient.cpp
g++ $(CFLAGS) -o bin/echoClient.o src/echoClient.cpp
.PHONY: clean
clean:
rm -f bin/*
What I need to to in order to make the program compile and run?
Do i need to download boost and put it in some folder?
Do i need to change the value LDFLAGS that inside the makefile to the download boost destination?
This is what i did so far, but it seems wrong because when I run make I get this error:
g++ -o bin/echoExample bin/connectionHandler.o bin/echoClient.o -L/Users/user/Downloads/boost_1_61_0
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in connectionHandler.o
boost::system::error_code::error_code() in connectionHandler.o
___cxx_global_var_init.2 in connectionHandler.o
boost::asio::error::get_system_category() in echoClient.o
___cxx_global_var_init.2 in echoClient.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in connectionHandler.o
___cxx_global_var_init.1 in connectionHandler.o
___cxx_global_var_init in echoClient.o
___cxx_global_var_init.1 in echoClient.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: *** [all] Error 1
Am i doing it OK?
I'm tring to run it both in mac and in windows
The folder boost_1_61_0 contains folders: boosts, libs, status, more, tools and more

Linker error only when using -O1 for boost::error_info in anonymous namespace

I'm working with a piece of code that has a boost::error_info typedef inside an anonymous namespace. The code compiles and links fine unless I use the -O1 flag. Here's a minimal example:
test.cpp
#include <boost/exception/all.hpp>
namespace {
typedef boost::error_info< struct tag_err_val, int > err_val;
}
int main() {
err_val(42);
}
This compiles and links fine with any of these invocations of clang:
$ clang++ test.cpp -O0 -o test
$ clang++ test.cpp -O2 -o test
$ clang++ test.cpp -O3 -o test
But if I use -O1 then this happens:
$ clang++ test.cpp -O1 -o test
Undefined symbols for architecture x86_64:
"std::__1::basic_ios<char, std::__1::char_traits<char> >::fill(char)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::exception_detail::object_hex_dump<boost::error_info<(anonymous namespace)::tag_err_val, int> >(boost::error_info<(anonymous namespace)::tag_err_val, int> const&, unsigned long) in test-30d00d.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 problem is 'fixed' by moving the typedef out of the anonymous namespace. But why is this link error only occurring for one optimization level? And what is causing it?
Note: I'm using boost 1.64 and Apple clang++ 8.1.0

Undefined symbols for architecture x86_64 "_r8_huge_"

I have a .f90 file which I compile with:
gfortran -c -o objs/mod_interp.o ../extern/mod_interp.f90 -g -fPIC -Imods -I../header_files -Jmods
The rest of the objects are compiled from F77 files, and then everything is linked with:
gfortran -o WIM2d.exec objs/p_WIM2d.o objs/mod_WIM2d_run.o objs/mod_interp.o objs/mod_file_utils.o objs/mod_gridinfo.o objs/mod_wim_init.o objs/mod_common_wim.o objs/mod_wim_prams.o objs/RTparam_outer.o objs/RTparam_fast.o objs/RTparam_hardcoded_v2.o objs/mod_RTparam_utilities.o objs/mod_adv_atten.o objs/mod_advect.o objs/mod_wavesice.o -g -fPIC -Imods -I../header_files
However I get the following error:
Undefined symbols for architecture x86_64:
"_r8_huge_", referenced from:
___mod_interp_MOD_pwl_interp_2d in mod_interp.o
"_r8vec_bracket5_", referenced from:
___mod_interp_MOD_pwl_interp_2d in mod_interp.o
ld: symbol(s) not found for architecture x86_64
I am working on a mac with OSX 10.10.
Any suggestions?

Undefined symbols for architecture x86_64: Eclipse Mac OSX

I'm trying to build my project in the eclipse luna cdt environment. It appears that the linker is having an issue with my code. I'm completely inexperienced with linkers and compilers and have no idea how to approach the problem. I tried compiling the code outside the IDE and have a similar problem. Here is the message that Eclipse gives me when I try to build the project. Any help would be much appreciated.
17:09:25 **** Build of configuration Debug for project Assignment 1 ****
make all
Building file: ../linkedList.C
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"linkedList.d" -MT"linkedList.d" -o "linkedList.o" "../linkedList.C"
Finished building: ../linkedList.C
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Assignment 1
Invoking: MacOS X C++ Linker
g++ -o "Assignment 1" ./linkedList.o ./main.o
Undefined symbols for architecture x86_64:
"LinkedList<int>::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
vtable for LinkedList<int> in main.o
"std::__1::basic_ostream<char, std::__1::char_traits<char> >& operator<<<int>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, LinkedList<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)
make: *** [Assignment 1] Error 1
17:09:27 Build Finished (took 1s.729ms)

Error building simple Qt5 application

I installed Qt 5.0.0 (qt-mac-opensource-5.0.0-clang-offline.dmg) on a Mac OS X 10.7.5 and now I'm trying to compile a "Hello World" application using Qt Creator 2.6.1.
The build process complains about a directory not found: /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib , followed by several linking errors:
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/mkspecs/macx-clang -I. -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtGui -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtCore -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o main.o main.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o hello_qt.app/Contents/MacOS/hello_qt main.o -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib -framework QtGui -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib -framework QtCore -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib'
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main.o
"QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)", referenced from:
_main in main.o
"QWidget::show()", referenced from:
_main in main.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in main.o
"QApplication::exec()", referenced from:
_main in main.o
"QPushButton::~QPushButton()", referenced from:
_main in main.o
"QLabel::~QLabel()", referenced from:
_main in main.o
"QApplication::~QApplication()", 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)
make: *** [hello_qt.app/Contents/MacOS/hello_qt] Error 1
It's important to note that the path /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib is not valid because the directory qtbase doesn't exist. The working path is /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib. I'm not referring to qtbase anywhere in my project, so this is probably being added by qmake.
As it turns out, the invalid qtbase path thing is really a Qt bug originally reported at QTBUG-28336.
The linking problem is due to my project not linking with QtWidgets, which is something we are going to have to do starting in Qt5. This is accomplished by adding the following line to your .pro file:
QT += widgets
i had the same problem and to be honest im not shure how i managed it to solve.
i think/guess i copied the needed folders from the sources into the matching 'clang_64' folders and that does the job.
soo long zai