Using 32 bit .a library file in 64 bit linux machine - c++

I am trying to use 32 bit .a files in a 64 bit machine. I compiled source code using gcc -m32 option. It gave following error
gcc -m32 *.c -Llib -lquanser_communications -Iinclude -o prg.o`In file included from /usr/include/wchar.h:27:0,
from include/quanser_types.h:16,
from include/quanser_communications.h:16,
from include/quanser_stream.h:11,
from stream_client.c:3:/usr/include/features.h:374:25:
fatal error: sys/cdefs.h: No such file or directory
After searching I got to this and thread and installed libx32gcc-4.8-dev and libc6-dev-i386 packages.
After installing those packages and running compilation gives following error
gcc -m32 *.c -Llib -lquanser_communications -Iinclude -o prg.o
lib/libquanser_communications.a: file not recognized: File truncated
How could I fix this issue ?
Thanks.

You're probably getting this error because your libquanser_communications is 64-bit and not 32-bit. You can't compile 32 bit against 64 bit code.
If you compiled libqunaser yourself, compile it with the -m32 flag (recursively, until you're done with all dependencies).
If not, get the 32 bit version of it

Related

Compile OpenGL with GCC 64-bit

I have a project that compiles with GCC 32-bit. I have been trying to migrate to GCC 64-bit on my native Windows machine (not through a VM). To do this I have downloaded w64devkit from https://github.com/skeeto/w64devkit/releases. My 32-bit install comes from https://sourceforge.net/projects/mingw/.
NOTE: Both installs cannot be active at the same time. Since the 32-bit version makes it into the path before we can add the 64-bit version through the environment variables, I modify the 32-bit MinGW folder name so that when the 64-bit version of GCC tries to use as.exe and ld.exe through the path, it will find the correct versions.
I have also downloaded glm, glew, and glfw for this project, and added folders to the path to get at least the 32-bit version working.
The working command line to compile the 32-bit version is as follows:
g++ -std=c++11 -O3 -ggdb src/main.cpp -o build/main -lopengl32 -L. -I"C:\lib\glm" -I"C:\lib\glew-2.1.0-win32\include" -I"C:\lib\glfw-3.3.8.bin.WIN32\include" "C:\lib\glfw-3.3.8.bin.WIN32\lib\libglfw3dll.a" "C:\lib\glew-2.1.0-win32\lib\Release\Win32\glew32.lib"
The following command line to compile the 64-bit version also works:
g++ -std=c++11 -O0 -ggdb src/main.cpp -o build/main -lopengl32 -L. -I"C:\lib\glm" -I"C:\lib\glew-2.1.0-win32\include" -I"C:\lib\glfw-3.3.8.bin.WIN64\include" "C:\lib\glfw-3.3.8.bin.WIN64\lib-mingw-w64\libglfw3dll.a" "C:\lib\glew-2.1.0-win32\lib\Release\x64\glew32.lib"
However whenever I try to run the executables, the 32-bit version runs and the 64-bit version gives me an error in a pop-up window. "The application was unable to start correctly (0xc000007b). Click OK to close the application."
When I try to run it in one of my debuggers I get a "Error: 32-bit processes are not supported". Another debugger says "During startup program exited with code 0xc000007b".
Clearly something is going horribly wrong, but I don't know what or where.

Compiling 32-bit code with 64-bit MinGW GCC [duplicate]

I've downloaded MinGW from this link x64-4.8.1-posix-sjlj-rev1 but when I try to build for x86 target I've lots of linkage errors... seems that only x64 lib are installed...
I've need to build for x86 and x64 platforms on windows... Have I to download both x64 and x86 or are some simpler ways?
Edit I'm using eclipse keplero as IDE
I've tryed to build myself a simple hello world program with g++ -m32 -std=c++11 test.cpp -o test32.exe and g++ -m64 -std=c++11 test.cpp -o test64.exe. And all is ok... So the problem was with eclipse... After a little a discovered that I need to use MYSY ( set in PATH ) and set -m32 also in the c++ linkage options...
Now all is fine.
I've also tryed to use NetBeans C++ as IDE... seems a gread IDE!!!
It is not multilib enabled. That's why you are not able to compile 32-bit(x86) program. You can get multilib enabled toolchain from following link:
For 64-bit machine: 64-Bit
For 32-bit machine: 32-Bit

Error in cross compiling for adding libpcap to mipsel

I compiled C and link libpcap
after adding the library. I use the following line to compile my code.
mipsel-openwrt-linux-gcc -c -Wall -I /home/osboxes/Downloads/OpenWrt-SDK-brcm47xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1/staging_dir/toolchai,n-mipsel_gcc-4.3.3+cs_uClibc-0.9.30.1/include -o sniffex.o sniffex.c
Output:
cc1: error: /home/osboxes/Downloads/OpenWrt-SDK-brcm47xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1/staging_dir/toolchain-mipsel_gcc-4.3.3+cs_uClibc-0.9.30.1/usr/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.3.3/../../../../mipsel-openwrt-linux-uclibc/sys-include: not a directory
cc1: error: /home/osboxes/Downloads/OpenWrt-SDK-brcm47xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1/staging_dir/toolchain-mipsel_gcc-4.3.3+cs_uClibc-0.9.30.1/usr/bin/../lib/gcc/../../lib/gcc/mipsel-openwrt-linux-uclibc/4.3.3/../../../../mipsel-openwrt-linux-uclibc/sys-include: not a directory
I tried also to do it with Makefile
I did something wrong. I find that the SDK was 32 bit and I have 64bit OS then I downloaded 64bit SDK and everything work well.

I want to use Clang on Windows to compile 64 bit code from C++ - Getting stdio.h file not found

I have installed the 64 bit MinGW, and put it into the C:\MinGW path. With the 32 bit MinGW I could compile OK, but then when I changed to the 64 bit version, to compile to 64 bit code, I still had problems, getting this error message:
test1.cc:1:10: fatal error: 'stdio.h' file not found
I have run this command to try to compile my example:
clang test1.cc -o test1.exe -v --target=x86_64
Using the below command fixed the issue for me
clang test1.cc -o test1.exe -v --target=x86_64-pc-windows-msvc

Getting a Botan library test program to compile under Windows 7 (MinGW, Code::Blocks)

I have been trying in vain to get this test program to compile
#include <botan/botan.h>
int main()
{
Botan::LibraryInitializer init;
}
I have downloaded library source from the website. I ran configure.py, which ran fine.
I then attempted to run MinGW-make
This is the error I got
c:\Botan-1.11.7>mingw32-make
g++ -m64 -pthread -fPIC -fvisibility=hidden -std=c++11 -D_REENTRANT -fstack-pro
tector -O3 -momit-leaf-frame-pointer -Wall -Wextra -Wstrict-aliasing -Wstrict-ov
erflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wold-s
tyle-cast -Wzero-as-null-pointer-constant -Ibuild\include -c C:\Botan-1.11.7\src
\lib\algo_base\scan_name.cpp -o build\obj\lib\src_lib_algo_base_scan_name.obj
C:\Botan-1.11.7\src\lib\algo_base\scan_name.cpp:1:0: warning: -fPIC ignored for
target (all code is position independent) [enabled by default]
C:\Botan-1.11.7\src\lib\algo_base\scan_name.cpp:1:0: sorry, unimplemented: 64-bi
t mode not compiled in
mingw32-make: *** [build\obj\lib\src_lib_algo_base_scan_name.obj] Error 1
I searched Google and any available forum I could find. I found prebuilt libraries for windows in a hidden folder on their site. However the package contained lib and dll files and not .a files which MinGW requires. I tries to use a program LIB2A which created a .a file. I have added this file into my code::blocks linker options. I also included the include folder.
When I try to compile I get this error.
C:\botan\include\botan\init.h|41|undefined reference to `_imp___ZN5Botan18LibraryInitializer10initializeERKSs'|
It seems like it cannot see the library with function definitions, but I am lost on where to go from here.
mingw32-make has the -m64 flag set, which means it's trying to build a 64 bit library. To build a 64 bit library, you'll need to get MinGW-w64.
When you ran configure.py, it likely set up your MakeFile to build a 64 bit library. You'll want to check what options are set in its output. This includes the option to build 32 bit or 64 bit. Either way, you'll want some variant of this: python configure.py --os=mingw --cc=gcc
This question had a similar error, and suggested using MinGW-w64, which will allow you to build a 64 bit library: Building 64 bit dll with MinGW 32 bit in Eclipse
In order to build with mingw32-make off the command line, you'll need to also add the MinGW-w64 bin directory to your Windows path, and likely remove the Code::Blocks packaged MinGW from your path to avoid conflicts. You'll still use mingw32-make to build the library with MinGW-w64; even though it's named mingw32-make, it will build 64 bit.
If you decide to build the library 64 bit, you'll need to build your application 64 bit as well, so you'll want to set up MinGW-w64 for Code::Blocks. To set MinGW-w64 up in Code::Blocks, see this question: Setting up MingW and Code::Blocks in Windows 8 64 bit.