Boost-MPI HelloWorld Compilation Issues - libstdc++

EDIT: solved, incorrect boost setup /facepalm
I have been trying to install boost-mpi on an old system/cluster.
After installing boost and using bjam --with-mpi, i tried to compile a hello_world example that came with the boost-mpi setup tutorial.
I supplied the mpi-autoconfig for bjam with mpic++ and when I compile using the following:
/../gnu/bin/mpic++ -I/home/user/boost_1_51_0 communicator.cpp -lstdc++ -L/home/user/boost_1_51_0/stage/lib -lboost_mpi -lboost_serialization
I receive the following errors:
libboost_serialization.so: undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::basic_istream<char, std::char_traits<char> >::_M_extract<unsigned short>(unsigned short&)#GLIBCXX_3.4.9'
So I guessed that GLIBCXX3.4.9 must have been found when building with bjam, but after
locate libstdc++.so
I used
"strings /path/to/libstdc++.so | grep LIBCXX"
and each one only had 3.4.8 as the latest version of GLIBCXX.
I am rather confused about this problem. Any help is appreciated!

This does indeed mean libboost_serialization.so was compiled with a newer version of GCC.
Are you sure you don't have another version installed? Is your locate database up to date? What does which g++ show?
Does it help if you put -lstdc++ last in the compilation command? Since liboost_serialization.so depends on libstdc++.so you should order them correctly.

Related

Getting started with GCC plugins

So after searching the web for a while, Ive decided to try here as it seems to be a good forum for discussion. Im trying to create a simple gcc plugin. The program code is attached in the end of this mail, but in plain english it registers the plugin and makes sure that the pragma_init function is called when pragmas are registered. It is here that I use c_register_pragma to intercept some of the pragmas.
I compile it using the example in http://gcc.gnu.org/onlinedocs/gccint/Plugins-building.html#Plugins-building. The compilation and linking works fine. However, when I load the plug-in I get:
gcc -c -fplugin=plugin.so test.c -o test.o
cc1: error: cannot load plugin plugin.so
plugin.so: undefined symbol: warning
What am I doing wrong? In addition, when including some header files (that will be required later), I get a lot of errors. For example, including "tree.h" yields (amongst 50 other errors):
/machmode.h:262:1: error: unknown type name 'class'
class bit_field_mode_iterator
^
/machmode.h:263:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
/plugin/include/tree.h:27:0,
from conftest.c:63:
/vec.h:220:8: error: field 'register_overhead' declared as a function
Anyone have a clue on what I am doing wrong?
Thank you
There are two problems here :
The error : "cannot load plugin plugin.so" means that you should add to your LD_LIBRARY_PATH the directory where you store your new shared library plugin.
The hundreds of errors you got with all the files in the include are resolved in my computer if you compile with g++ instead of gcc (not sure to understand why thought)
Which version of GCC are you using, both to compile your plugin, and to use the plugin? Run simply
gcc -v
without any other program argument to find out!
Did you install the appropriate package for GCC plugin development (on Debian or Ubuntu, it might be gcc-4.7-plugin-dev, but adapt the 4.7 version to your particular version of GCC)?
Did you install all the dependencies needed to build your GCC (on Debian or Ubuntu, apt-get build-dep gcc-4.7 gcc-4.7-plugin-dev)?
Recent versions of GCC (notably many GCC 4.7 shipped by distributions, and all GCC 4.8) are compiled by a C++ compiler, not a C compiler.
You may check how was your GCC built (in C or in C++) by running
nm -D -C $(gcc -print-file-name=cc1)
If that command shows typed C++ manged names, e.g. execute_ipa_pass_list(opt_pass*) instead of just execute_ipa_pass_list your GCC has been compiled with a C++ compiler (probably g++)
So you may need to use g++ (not gcc) to compile your GCC plugin.
As I commented, did you consider using MELT (a domain specific language to extend GCC) to extend or customize your gcc compiler?
I suggest downloading the very latest http://gcc-melt.org/melt-plugin-snapshot.tar.bz2 since I will release the next MELT in a few weeks for GCC 4.7 and 4.8
And don't expect to change the parsing behavior of your GCC with a plugin. That is not really possible (GCC provides only plugin hooks to add your builtins and pragmas, not to extend the parsed syntax).

Building a program (sscep) against OpenSSL: undefined reference to '[...]'

I am trying to build a tool called sscep (http://www.klake.org/~jt/sscep/) for Windows. It does not run natively and I have a "patch" that changes sscep to make it compile on Windows.
After applying the patch, it does compile perfectly but the linker screws. I am using gcc in minGW/msys
The original messsage was that it couldn't find the crypto lib so I added the library with "-L../openssl-mingw/lib" which then didn't create any more errors. I also have the command line switch -lcrypto in my command: gcc -L../openssl-mingw/lib -lcrypto sscep.o init.o net.o sceputils.o pkcs7.o ias.o fileutils.o -o sscep.In this directory is a libcrypto.a. OpenSSL itself was compiled with the exact same compiler just running ./config && make && make test && make install. Also the sources were extracted using the minGW tar and not 7-zip.
After following all documentation this is my (truncated) output:
sscep.o:sscep.c:(.text+0x83): undefined reference to `WSAStartup#8'
sscep.o:sscep.c:(.text+0xa5): undefined reference to `WSACleanup#0'
sscep.o:sscep.c:(.text+0x3d5): undefined reference to `BIO_new_mem_buf'
sscep.o:sscep.c:(.text+0x3e0): undefined reference to `ASN1_INTEGER_new'
sscep.o:sscep.c:(.text+0x414): undefined reference to `a2i_ASN1_INTEGER'
sscep.o:sscep.c:(.text+0x432): undefined reference to `ASN1_INTEGER_to_BN'
sscep.o:sscep.c:(.text+0x448): undefined reference to `BN_bn2dec'
sscep.o:sscep.c:(.text+0xb7e): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xbaf): undefined reference to `EVP_bf_cbc'
sscep.o:sscep.c:(.text+0xbda): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xc02): undefined reference to `EVP_des_ede3_cbc'
sscep.o:sscep.c:(.text+0xc48): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xc79): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xca1): undefined reference to `EVP_sha1'
This goes on for every file in there and supposedly every function called.
Searching here and google resulted in a missing library but omitting the -L directive from above I get another error about not finding libcrypto. So I assume that the library is actually found but somewhat with wrong addresses or something?
Here my compiler/linker knowledge actually ends.
If it is possible that the patch is responsible for that (which I do not believe since these are all openssl functions and the compiling works) then I can provide you with it.
Edit: Is there any information that I should provide so someone can help me? The version of openssl is 1.0.1 if this makes any difference.
On this topic: If it does make a difference, could this error occur because of a wrong version. As far as I understand linker theory, this error should not originate from a wrong version unless all of the below functions were replaced by differently named ones (but then the compiler would have complained, I guess?).
Another addition: Since I am on a 64 bit Windows 7, I tried to compile it with -m32 flag but that did not help. I assume since mingw is already 32 bit only, I can't even build x64. Another question is whether it is a problem that I am running in a virtualized environment on an AMD Opteron while openssl is built with the command "-march=i486"?
With some help I could finally figure this out! It was a problem of the order AND a problem of missing libraries. The combination killed me.
The libraries had to be -lcrypto -lws2_32 -lgdi32 not just -lcrypto. Furthermore, I had to append the libraries after the object files, so: $(CC) $(CFLAGS) $(OBJS) -lcrypto -lws2_32 -lgdi32 -o $(PROG) was the right make line.
Finally with this, it compiles fine. I didn't even need any architecture flags and such.

GCC 4.7, including <stdatomic.h>

I've just compiled GCC 4.7 to work with stdatomic.h, but I can't seem to -I it. stdatomic.h seems to live in /usr/include/c++/4.4.3, but then the linker tells me it needs a bunch of other files in dirs nearby. If I -I all of them, I still get the error undefined reference to atomic_flag_clear_explicit. Any ideas how I'm supposed to link this right?
First, if you are compiling with GCC 4.7 you should not be including or linking anything from a directory from GCC 4.4.
Second, -I only affects the search path for header files. "undefined reference" is a linker error and usually means it hasn't found the right library. You change the library search path with -L. The linker didn't say it didn't find a library with the right name, it says it didn't find a symbol, so clearly the library it did find didn't have that symbol. I'd suggest you have a versioning problem, perhaps caused by a installation problem.
The <stdatomic.h> header in GCC 4.4 and 4.5 was from an early draft of C++0x atomics, but is not part of the final standard, so it was removed from libstdc++.
The C++ compiler supports C++11 atomics via the C++11 <atomic> header, so you should use that header in C++ code.
When the C compiler supports C11 atomics, the <stdatomic.h> header will be provided again.
Using this command solved the problem for me:
$ scl enable devtoolset-7 bash
I got the same error as you when entering sudo make altinstall for installing Python 3.8.5 on CentOS 7.

Problem linking with Boost.Filesystem

I am trying to use the functions from boost::filesystem to change my current working directory (and create it if necessary). I am getting linking errors:
SBDir.cpp:(.text+0x23): undefined reference to `boost::system::generic_category()'
SBDir.cpp:(.text+0x2f): undefined reference to `boost::system::generic_category()'
SBDir.cpp:(.text+0x3b): undefined reference to `boost::system::system_category()'
But I am linking against the boost libraries??!? I use the following:
-lboost_system -lboost_system-mt -lboost_filesystem -lboost_filesystem-mt
And I know it can find them because with -Wl, -t I get:
-lboost_system (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_system.so)
-lboost_system-mt (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_system-mt.so)
-lboost_filesystem (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_filesystem.so)
-lboost_filesystem-mt (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_filesystem-mt.so)
FWIW: I'm using gcc Ubuntu 4.4.3-4ubuntu54.4.3.
I had this same error message with boost 1.46 (standard with Ubuntu 11.10) and I had to add -lboost_system which I didn't need in 11.04 and boost 1.42. It doesn't answer your question but possibly of interest to others brought here by googling the error message.
So I couldn't figure out what went wrong -- so I tried un-installing the Ubuntu boost package and building it from scratch. I upgraded to 1.45.0 & now everything links. Not sure whether this was a version specific problem or not, but if I learn more later I'll come back and update.

Help on Compiling on AIX

Is there a site where I can find the symbols used in a particular library and its version.
For e.g. I m trying to compile some code on AIX using gcc, and it throws me a lot of undefined symbol errors
For example, here is an output:
ld: 0711-317 ERROR: Undefined symbol: .__fixdfdi
ld: 0711-317 ERROR: Undefined symbol: .__divdi3
ld: 0711-317 ERROR: Undefined symbol: .__moddi3
ld: 0711-317 ERROR: Undefined symbol: .__floatdidf
ld: 0711-317 ERROR: Undefined symbol: .__umoddi3
ld: 0711-317 ERROR: Undefined symbol: .__udivdi3
ld: 0711-317 ERROR: Undefined symbol: .__fixunsdfdi
Where do I go to find where these symbols are.
If I run the same gcc command on Linux, it runs fine.
I tried including -lgcc also but then again it throws undefined symbols for some register_frame ...blah blah...
and I m getting sick of AIX.
Any help on this would be appreciated..and please don't bother Googling on this issue.
You will end up no where.
Many have asked this kind of questions but no answers.
Thanks
It's been a long time since I compiled anything on AIX (thankfully) and I do feel your pain having spent a good year or so trying to get our company's JNI and other software libraries built on AIX.
I do seem to remember that GCC never worked particularly well as it always came up with similar errors. Is there any option to use the native compiler (xlC)?
Failing that I would check the ordering of your libraries, it plays a big part in making stuff work properly..
I take it that you have use the nm utility to iterate through every library in /usr/lib (etc) to find where the missing symbols are located?
Those are math symbols. Try adding -lm to your link line.
This is because you used the gcc to compile a library you want to link to a code compiled with xlc. Or at least is my case
You have 2 options:
use the xlc instead of gcc for all the compilation (don't mix gcc and xlc)
compile with xlc but calling also the gcc libraries, for instance:
sudo find / -name libgcc.a
/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/libgcc.a
/opt/IBM/xlC/13.1.0/bin/xlC -g -o MyBIN MyBIN.o -L/usr/etctera -
L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/ -lgcc -letcetera
Mostly questions:
Which version of GCC?
Which version of AIX are you on?
Which version of AIX was your copy of GCC built for?
What exactly is the link line you are using?
I've seen that sort of error when using a version of GCC compiled on a down-version of AIX. For example, if the GCC was compiled for AIX 4.3.3 and is being run on AIX 5.x. Usually, if GCC was compiled on an up-version of AIX, it won't run on the down-version, so that is unlikely to be the problem.
One other (rather unlikely) possibility: is your GCC installed where it was compiled to expect to be installed? When you build it, you specify (possibly implicitly) the install location (by default, under /usr/local). If you have your copy installed somewhere else, but there's an old GCC in /usr/local and your copy expects to be installed in /usr/local, then you can run into this sort of problem. This is much less likely than version mismatching.
Listed external symbols are from libgcc so add of -lgcc is correct. And register_frame also is part of libgcc but only for 32-bit. Check if you use the same bit depth mode for you compiler, linker and libraries.

Resources