Building 32-bit FCGI++ binaries in 64-bit environment in Ubuntu 13 - c++

Good afternoon.
I'm trying to build 32-bit fcgi++ binaries under my 64-bit env. I configured FCGI++ in the following way:
CC="gcc -m32" ./configure
After typing 'make' I see the some building process and the following errors at the end (snippet is here):
gcc -m32 -shared fcgio.lo -Wl,--rpath -Wl,/home/eotovchits/Downloads/fcgi/fcgi-2.4.1-SNAP-0311112127/libfcgi/.libs -Wl,--rpath -Wl,/usr/local/lib /home/eotovchits/Downloads/fcgi/fcgi-2.4.1-SNAP-0311112127/libfcgi/.libs/libfcgi.so -Wl,-soname -Wl,libfcgi++.so.0 -o .libs/libfcgi++.so.0.0.0
/usr/bin/ld: i386:x86-64 architecture of input file fcgio.lo' is incompatible with i386 output
fcgio.lo: In function__static_initialization_and_destruction_0':
/usr/include/c++/4.8/iostream:74: undefined reference to std::ios_base::Init::Init()'
/usr/include/c++/4.8/iostream:74: undefined reference tostd::ios_base::Init::~Init()'
...................... a lot of similar lines ...........................
fcgio.lo: In function ~basic_ios':
/usr/include/c++/4.8/bits/basic_ios.h:276: undefined reference tovtable for std::basic_ios >'
/usr/include/c++/4.8/bits/basic_ios.h:276: undefined reference to std::ios_base::~ios_base()'
/usr/include/c++/4.8/bits/basic_ios.h:276: undefined reference tovtable for std::basic_ios >'
/usr/include/c++/4.8/bits/basic_ios.h:276: undefined reference to std::ios_base::~ios_base()'
fcgio.lo: In functionfcgi_istream::~fcgi_istream()':
/home/eotovchits/Downloads/fcgi/fcgi-2.4.1-SNAP-0311112127/libfcgi/../include/fcgio.h:120: undefined reference to `operator delete(void*)'
/usr/bin/ld: fcgio.lo: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status
I assume that I need some additional 32-bits building environment to make the 32-bits binaries (along w/ all the needed 3rd-party libraries, .a-s and .so-s)
Do you know how can i set up such environment locally along with native 64-bit environment and build my fcgi++ binaries for 32-bits environment?
Thank you.

on Ubuntu you can install the libraries for i386 along the x64 ones by appending":i386" at the end oh the name of the package you want to install (assuming you are using apt-get to install the lib).
here is an example of how to do it:
https://askubuntu.com/questions/60751/is-it-possible-to-have-32-bit-libraries-installed-on-a-64-bit-system
And here how to install the compiler for 32 bits (well the STL and other stuff):
http://en.kioskea.net/faq/1137-compiling-testing-in-32-bit-on-ubuntu-x86-64

Related

Numerous LD linking errors while linking against downloaded package

I've been trying to compile an open-source C++ project Typesense, which has this list of dependencies:
Snappy
zlib
OpenSSL (>=1.0.2)
curl
ICU
brpc
braft
Host and target OS is Debian Linux. Compilation is handled via cmake->make sequence of commands. I was able to install some of dependencies through a package manager (I believe they reside in /usr/lib then), the last two I had to compile on my own, I put them in /usr/local/lib.
All the dependencies were successfully compiled, and the target project compiled too.
When it comes to linking stage, I get numerous errors like
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-easy.o): in function `global_init':
(.text+0x94): undefined reference to `libssh2_init'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-http2.o): in function `on_header':
(.text+0x6c): undefined reference to `nghttp2_session_get_stream_user_data'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-socks_gssapi.o): in function `check_gss_err.part.0':
(.text+0x57): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x77): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x9b): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xcf): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xef): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x112): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x17e): undefined reference to `gss_release_buffer'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-curl_rtmp.o): in function `rtmp_connect':
(.text+0xd4): undefined reference to `RTMP_Connect1'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-openldap.o): in function `ldap_connecting':
(.text+0x111): undefined reference to `ldap_result'
There is at least a hundred of such errors. I'm not at all proficient with Linux and complex building of projects. How do I possibly fix linking errors for libraries that I just downloaded through a package manager?
EDIT: Libraries, that cmake seems to link against at the end:
braft;
brpc;
/usr/lib/x86_64-linux-gnu/libleveldb.a;
glog;
h2o-evloop;
iconv;
/usr/lib/x86_64-linux-gnu/libcurl.a;
for;
/usr/lib/x86_64-linux-gnu/libicui18n.a;
/usr/lib/x86_64-linux-gnu/libicuuc.a;
/usr/lib/x86_64-linux-gnu/libicudata.a;
rocksdb;
/usr/lib/x86_64-linux-gnu/libsnappy.a;
/usr/lib/x86_64-linux-gnu/libz.a;
rt;
/usr/lib/x86_64-linux-gnu/libssl.a;
/usr/lib/x86_64-linux-gnu/libcrypto.a;
pthread;
dl;
-static-libgcc;
-static-libstdc++;
gflags_shared;
/usr/lib/x86_64-linux-gnu/libprotobuf.a;
-lpthread
Your dependency list is incomplete. It only includes immediate dependencies.
Your version of libcurl is built with ssh, gssapi, nghttp2, ldap, rtmp and possibly other goodies, none of which you are linking against. You are using static linking, and static libraries do not have a built in concept of dependencies. This means you have to manually include all the non-immediate dependencies in your build command. You can get the impression of how many more libraries you need to include by executing this command
ldd /path/to/your/libcurl.so
and observing the list of dependencies your libcurl has.
The same thing may be true about other libraries you use.
One way to resolve the issue is to use dynamic linking. This way you just link to immediate dependencies, and they know their dependencies.

Compiling Box2D HelloWorld on Ubuntu 12.04

I am planning to use Box2D in my C++ project. I have downloaded the latest version (v2.3.0.7 when asking this question) of Box2D and built it successfully. I can run the Testbed without any errors.
Now, I am trying to build the HelloWorld.cpp example, which resides in HelloWorld folder in Box2D source files but I can't compile this example.
Below is my command for compiling:
g++ -g -Wall -L/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Build/Box2D -lBox2D -I/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D HelloWorld.cpp -o Hello
And this is the output I get:
/tmp/cc2U314E.o: In function `main':
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:37: undefined reference to `b2World::b2World(b2Vec2 const&)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:46: undefined reference to `b2World::CreateBody(b2BodyDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:52: undefined reference to `b2PolygonShape::SetAsBox(float, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:55: undefined reference to `b2Body::CreateFixture(b2Shape const*, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:61: undefined reference to `b2World::CreateBody(b2BodyDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:65: undefined reference to `b2PolygonShape::SetAsBox(float, float)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:78: undefined reference to `b2Body::CreateFixture(b2FixtureDef const*)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:92: undefined reference to `b2World::Step(float, int, int)'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:104: undefined reference to `b2World::~b2World()'
/home/viki/Desktop/collision_test/test/HelloWorld.cpp:104: undefined reference to `b2World::~b2World()'
/tmp/cc2U314E.o: In function `b2PolygonShape':
/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Box2D/Collision/Shapes/b2PolygonShape.h:87: undefined reference to `vtable for b2PolygonShape'
/tmp/cc2U314E.o: In function `~b2PolygonShape':
/home/viki/Desktop/collision_test/Box2D_v2.3.0/Box2D/Box2D/Collision/Shapes/b2PolygonShape.h:28: undefined reference to `vtable for b2PolygonShape'
collect2: ld returned 1 exit status
I'm using
-L flag for searching for libBox2D.a
-l flag for linking Box2D
-I flag for pointing to the Box2D headers directory
What am I missing? Is there any specific library or command argument I am supposed to add?
Put the -lBox2D behind the HelloWorld.cpp
If you have built your project properly the HelloWorld example will be automatically built for you. There's a CMakeLists.txt file in the example folder just run cmake CMakeLists.txt in the folder and then run make. Prior to this you must have built and installed Box2D library. Here is what I did:
I entered the Build directory within the Box2D and typed the following command:
cmake -DBOX2D_INSTALL=ON -DBOX2D_BUILD_SHARED=ON -DCMAKE_INSTALL_PREFIX=/opt/Box2D ..
Then I went one level up to Box2D directory and ran make then sudo make install.
Then I entered the HelloWorld directory and it was automatically built. I didn't have to build it manually. Also this is the output from make that showed the example was built:
Linking CXX static library libBox2D.a
[ 42%] Built target Box2D
[ 43%] Building CXX object HelloWorld/CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o

OpenSSL compiles failed on x86 thought was successful for x86_64

I'm trying to compile my project for x86 and x86_64 architectures on Windows. Using 64bit GCC from mingwbuilds project (4.8.1 rev 5), OpenSSL 1.0.1e compiles and links successfully, but using 32bit version of same compiler I got undefined references:
libcrypto.a(cryptlib.o):cryptlib.c:(.text+0x391): undefined reference to `OPENSSL_cpuid_setup'
libcrypto.a(mem.o):mem.c:(.text+0x859): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md2_dgst.o):md2_dgst.c:(.text+0x156): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md2_one.o):md2_one.c:(.text+0x59): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md4_one.o):md4_one.c:(.text+0x56): undefined reference to `OPENSSL_cleanse'
libcrypto.a(md5_one.o):md5_one.c:(.text+0x56): undefined reference to `OPENSSL_cleanse'
libcrypto.a(sha_one.o):sha_one.c:(.text+0x56): more undefined references to `OPENSSL_cleanse' follow
libcrypto.a(eng_all.o):eng_all.c:(.text+0x4): undefined reference to `OPENSSL_cpuid_setup'
libcrypto.a(eng_rdrand.o):eng_rdrand.c:(.text+0x4e): undefined reference to `OPENSSL_ia32_rdrand'
libcrypto.a(eng_rdrand.o):eng_rdrand.c:(.text+0x81): undefined reference to `OPENSSL_ia32_rdrand'
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe: libcrypto.a(eng_rdrand.o): bad reloc address 0x4 in section `.data'
collect2.exe: error: ld returned 1 exit status
OpenSSL is configured like this:
# on x86_64:
./Configure mingw64 -fPIC -O3 --prefix=/mingw shared enable-ec_nistp_64_gcc_128
enable-krb5 enable-md2 enable-rc5 enable-rfc3779 no-asm
# and for x86:
./Configure mingw -fPIC -O3 --prefix=/mingw shared \
enable-krb5 enable-md2 enable-rc5 enable-rfc3779 no-asm
Found it myself :) This is where exports are prevented for i386 when no assembler used. Specifically:
#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
#define OPENSSL_CPUID_SETUP
#if defined(_WIN32)
typedef unsigned __int64 IA32CAP;
#else
typedef unsigned long long IA32CAP;
#endif
void OPENSSL_cpuid_setup(void)
{ ...
So, we need an assembler for x86. I Installed NASM and the library compiles successfully.

Error in linking external libraries

I downloaded TripleBit's source code from http://grid.hust.edu.cn/triplebit/TripleBit.tar.gz.
It required me to install two libraries:
i) boost-1.39.0.tar.gz
ii) raptor-1.4.21.tar.gz
I installed them using :
sudo apt-get install libboost-dev
sudo apt-get install libraptor-dev
However, after I entered into TripleBit's directory and ran "make". I go the following errors:
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:38: undefined reference to `raptor_init'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:39: undefined reference to `raptor_new_parser'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:40: undefined reference to `raptor_set_statement_handler'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:42: undefined reference to `raptor_uri_filename_to_uri_string'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:43: undefined reference to `raptor_new_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:44: undefined reference to `raptor_uri_copy'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:45: undefined reference to `raptor_parse_file'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:47: undefined reference to `raptor_free_parser'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:48: undefined reference to `raptor_free_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:49: undefined reference to `raptor_free_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:50: undefined reference to `raptor_free_memory'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:52: undefined reference to `raptor_finish'
collect2: ld returned 1 exit status
make: *** [bin/lrelease/buildTripleBitFromRDF] Error 1
The library files which reside within /usr/local/lib are:
libboost_filesystem.so, libraptor.a, libraptor.la, libraptor.so, libraptor.so.1
and libraptor.so.1.2.0
Also the files which reside within /usr/lib are:
libraptor.a, libraptor.la, libraptor.so, libraptor.so.1, libraptor.so.1.2.0,
libraptor2.so.0, libraptor2.so.0.0.0, librasqal.so.3, librasqal.so.3.0.0, librdf.so.0,
librdf.so.0.0.0, librest-0.7.so.0, librest-0.7.so.0.0.0.
Can someone please help me in finding out the error.
I ran it on ubuntu 12.04
Look into TripleBit Makefile. You are missing -lraptor linker option. This entry should be returned by raptor-config --libs.
You can also run nm tool against libraptor.a file and check if it wasn't compiled with RAPTOR_DISABLE_V1 option.
Look into TripleBit Makefile, you can remove the "BuildTripleBitFromRDF" in line 82(modules := ..), so that you can escape the errors, but the "BuildTripleBitFromRDF" will not build into the executables. So when the dataset you download is a RDF dataset, You can use raptor to convert RDF dataset into N3 dataset, and then use the buildTripleBitFromN3 tool to go on.
The probable problem is the wrong installing in raptor.

Linker error: undefined reference to symbol 'pthread_rwlock_trywrlock##GLIBC_2.2.5'

I've been developing with CentOS, Qt 4.7, and GCC 4.4
I've just installed Red Hat Developer Toolset 1.1 which includes GCC 4.7.2, and at the end of make, I get an error
/usr/bin/ld: ../../bin/Solo: undefined reference to symbol 'pthread_rwlock_trywrlock##GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_rwlock_trywrlock##GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
I'm guessing that Qt threads is referencing to that. How can I fix it?
You want to compile with -pthread which does more than just link with libpthread:
Adds support for multithreading with the pthreads library. This
option sets flags for both the preprocessor and linker.
You just need to add CONFIG += thread to your .pro file.
Read the note: try to add /lib64/libpthread.so.0 into Makefile (-lpthread after gcc command, or /lib64/libpthread.so.0 after ld (or after gcc -shared)), or something like LIB += -lpthread if there's such definition somewhere.
See also: Adding external library into Qt Creator project and http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project
Btw, post your Makefile, so somebody will be able to point to exact line.
In my little laptop Linux (where I have a mixed bag of libraries),
I just had to add
LDFLAGS=-lpthread
AT THE END of the configure command arguments.
After that, make did its job perfectly (With the existing libraries).
I received similar 'Linker error: undefined reference to symbol' errors attempting to compile and install Python-3.7.2 on FreeBSD 12.
/usr/bin/ld: error: undefined symbol: _Py_GetGlobalVariablesAsDict
/usr/bin/ld: error: undefined symbol: _PyCoreConfig_AsDict
/usr/bin/ld: error: undefined symbol: _PyMainInterpreterConfig_AsDict
Resolved by passing LDFLAGS=-lpthread directly to make of lang/python37 or by adding to /etc/make.conf.
If using portmaster to install/update use -m to pass the arguement to make e.g.portmaster -a -m 'LDFLAGS=-lpthread'