g++ version 11 on Mac: library symbol not found - c++

I am trying to compile a shared library (c++ numpy extension) using the adept library for automatic differentiation. I get this error:
ImportError: dlopen( xxx/build/lib.macosx-10.9-x86_64-3.9/xxx.so, 0x0002): symbol not found in flat namespace '___emutls_v._ZN5adept21_stack_current_threadE'
how can I resolve this symbol?
This is the configuration used in "setup.py":
os.environ["CC"] = "g++-11"
os.environ["CXX"] = "g++-11"
extra_compile_args = ["-std=gnu++20", "-Wall", "-Wextra", "-O3", "-fPIC" , "-pthread"]
libraries=['glog', 'lapack', 'ceres', 'm', 'stdc++', 'gcc_eh', 'adept'],
language='c++20',
thank you for your suggestions!
I tried to add "gcc_eh" to solve issues with "emutls", but it obviously hasn't helped. I tried to link statically against adept.a, which didn't help either.

Related

GNU GMP with Matlab and mex - Library Problems

I am using Matlab (R2015a) together with Windows SDK 7.1 to compile a single C++ source file with Matlab's "mex" functionality. This works all fine.
However, in this C++-file, I'd like to use the GNU GMP library (arbitrary precision arithmetic/bigint), since I would appreciate some big integer calculations.
Therefore, i downloaded gmp-6.0.0 and set up the Cygwin toolchain to compile my GMP libraries for my Win-7 (64-bit) machine.
I compile/configure GMP this way in Cygwin:
$ configure --host=none-pc-cygwin --enable-alloca=malloc-notreentrant --enable-cxx --enable-static --disable-shared
$ make
$ make check
$ make install
... which gives me the header- and library files without errors or problems (gmp.h, gmpxx.h) as well as the libraries (libgmp.a, libgmpxx.a).
In my C++-program, I include the header:
#include "gmpxx.h"
... and i copy the libraries/headers to the same matlab working directory.
In my C++-code, I now try to use the GMP library, e.g. like this:
mpz_t val1;
mpz_init(val1);
I then call the matlab/mex/Windows SDK compiler (in Matlab) like so:
mex TestProgram.cpp -v libgmp.a libgmpxx.a
... which returns the following linker error:
Creating library TestProgram.lib and object TestProgram.exp
TestProgram.obj : error LNK2019: unresolved external symbol __gmpz_init referenced in function mexFunction
TestProgram.mexw64 : fatal error LNK1120: 1 unresolved externals
... And I do not know why it does this. Apparently, there are functions missing in the GMP library I compiled (?)... but why? Or is it a problem between mex and the windows SDK compiler?
Any suggestions of how to debug this? I already searched extensively, but the combination of mex and GMP is rarely used ==> little search results :-/
Edits:
Do I have to supply/link an additional library/DLL since Cygwin is used to compile?
Could it be a name mangling issue? (I also tried a purely C-based fuction/compilation, but with the exact same result)
If I compile a dynamic library with Cygwin (and supply the DLLs to matlab), I get the same linker error
Best and many thanks!
Mario

gnat gprbuild : how to build a dynamic dll and link with a static c++ library

I have a full Ada project I want to build to get a dynamic dll.
Therefore I have to link it with another static library (myanotherlibrary.lib).
I use this command line :
gprbuild -d "D:\My_grp_project\My_grp_project.gpr"
Here the content of the .gpr :
project My_grp_project is
Architecture := "x86";
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use "dll\" & Architecture;
for Library_Ali_Dir use "ali\" & Architecture;
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Object_Dir use "obj\" & Architecture;
package Linker is
for Default_Switches ("Ada") use ("-L.", "-lbar");
end Linker;
end My_grp_project;
I put "myanotherlibrary.lib" in the directory "D:\My_grp_project\", but it still doesn't link: "undefined reference to ..."
Could anyone help me please ?
Regards
Glen
Looking at the docs, I think you should be using the Library_Options attribute instead of package Linker:
for Library_Options use ("-L.", "-lbar”);
(I’m confused - do you mean myanotherlibrary.lib or bar.lib?)
I’d be a bit concerned about using a static library from a dynamic library: I’d expect the dynamic library to be built with -fPIC or equivalent switch to get position-independent code, so that the same loaded library binary can be seen at different addresses in each of the executables using it.
Here the solution I finally found.
It is not possible to link static library compiled with MSVC. I had to compile my static library with GCC (same version as the one included in GNAT).
I had to add "Library_Options" options, without "-L" and "-l" arguments (another problem I passed). Note that package Linker is not taken into account while building a dynamic library. Note also that paths shall have no spaces !
project My_grp_project is
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use “dll";
for Library_Ali_Dir use "ali";
for Object_Dir use "obj";
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Library_Options use ("path\myanotherlibrary.a", "path_to_GNAT\libstdc++.a");
end My_grp_project;
I builded the project in the GPS (default option) : "Build All"
In result I do have my dynamic library "libMy_grp_project.dll"
Voilà.
Thanks !

How to use 'boost_python-vc110-mt-gd-1_54.lib' in C++?

I am trying to use BoostPython to write a program in C++.
My presettings are:
a. Win32 Console Application.
b. Property->C/C++->General->Additional Include Directories->C:\Python27\include;C:\Program Files\boost\boost_1_54_0;
c. Property->Linker->General->Additional Library Directions->C:\Python27\libs;
d. Microsoft Visual Studio 2012 Express Version + Python 27 + Boost 1.54
And my code is like follows:
#include <boost/python.hpp>
using namespace boost::python;
int main( int argc, char ** argv )
{
return 0;
}
As you can see, this code is with an empty main function. And I got an error message
error LNK1104: cannot open file 'boost_python-vc110-mt-gd-1_54.lib'
I checked the installation of boost ('bootstrap.bat'+'bjam.exe'), and I've searched within the folder where boost library installed for 'boost_python-vc110-mt-gd-1_54.lib', but found nothing.
I looked for some similar posts, unlike my problem, the lib file they missed was with a prefix 'lib'. On the other hand, I found this post is very similar to mine. But I found the OP made a mistake when he/her solve his/hers problem. That is, Boost is compatible with python 2.2 and its newer versions. And the rest of his answer is not helpful to me.
I guess this problem could because either I've done something wrong during installation, or I was wrong when I link the libs to my application.
Can anyone help me out of this? A detailed solution will be great. Many thanks. :)
==============================================================
EDIT:
I've reinstalled the Boost with a prebuilt binary file. Now I can link to the lib file the compiler asked for. However, new problems are raised. Now I have two new errors:
error LNK2001: unresolved external symbol __imp___Py_NoneStruct
error LNK1120: 1 unresolved externals
When I comment out the line #include <boost/python.hpp>, the above errors are gone.
I really cannot figure out the reason. Can anyone help me with this? Many thanks.
You've added the C:\Python27\libs folder to you linker settings, but that doesn't have the boost files.
You need to run boost's bjam to generate the boost library files. Lots of boost is header only, but there are some libraries which you will need to build.
When you have done that you need to add the directory to
"Property->Linker->General->Additional Library Directories"
I've found out the error is raised because the Boost library was not properly installed in my computer. Actually, the key is bjam, and it must be run to build all these necessary libraries.
I would suggest anyone else that encounter with this problem, if you don't know how to run a bjam properly, go to search for a prebuilt binary file of Boost. That could save you a lot of time.

'g++-dw2' is not recognized as an internal or external command,

When I try to use gcc 4.6.2 with my qt I'm getting following error:
'g++-dw2' is not recognized as an internal or external command.
In Qt's pro file I have added:
QMAKE_CXXFLAGS += -std=c++0x
QMAKE_CXX = g++-dw2
QMAKE_LINK = g++-dw2
If I don't add those two lines I'm getting error: undefined reference to _unwindSomething
Does anyone knows how to solve it?
To solve the problem at hand:
If g++-dw2 is not already on your system, then you need to install it. Then you need to add it to your path or at least tell Qt the full path to the executable.

Problem in Dynamic linking on tcl library

Hi All
I have linked Tcl and Tk statically as following while linking with
gcc 443
/xxx/tcl_libs/8.5.9/lib/libtk8.5.a /xxx/tcl_libs/8.5.9/lib/
libtcl8.5.a
but when i tried to link it dynamically as following
-L/xxx/tcl_libs/8.5.9/lib/ -ltcl8.5 -L/xxx/tcl_libs/8.5.9/lib/ -ltk8.5
I am getting following error
/tools/linux64/gcc-4.4.3/bin/../lib/gcc/x86_64-unknown-linux-gnu/
4.4.3/../../../../x86_64-unknown-linux-gnu/bin/ld: tkMain.o: in
function main:../../..//tkMain.c:33: error: undefined reference to
'TclInitSubsystems'
One point when i tried to link tcl static an tk dynamic it works. I
checked it by ldd.
Please help.
Try moving them to /usr/lib to see if it is a path specification problem. If by doing so it works, you need to check how you are specifying ld paths.