3
votes

So I am trying to compile a c++ program and have the executable be 32-bit instead of 64-bit. The system (using a program to simulate a system) I want to run it on is 32-bit and seeing as compiling the program yields 64-bit ELF files I cannot run them. I have added the -m32 flag to the makefile and when compiling i get the following errors:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so when searching for -lstdc++ /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a when searching for -lstdc++ /usr/bin/ld: cannot find -lstdc++

when using sudo apt install -lstdc++ it simply says it cannot find the library. Anybody perhaps able to give me some direction? I am running all of this using remote wsl in visual studio code on a windows 10 machine. Ultimately I just want the compiled executables from this program to be 32-bit ELFs instead of 64-bit.

This is the make file The program im trying to compile is a benchmark suite located here https://github.com/alifahmed/hopscotch. This is the makefile otherwise located in /cpu/2_bandwidth:

TARGET =    bandwidth

.PHONY: all clean $(TARGET)

# directories
INC_DIR = ../include
KERN_DIR = ../kernels
CMN_DIR = ../common
OBJ_DIR = obj


# compiler flags ADDED -m32 FLAG
CXX = g++
CXXFLAGS = -m32 -O3 -fopenmp -march=native -I$(INC_DIR) -std=c++14 $(USER_DEFS)


# header files
HEADERS = $(wildcard $(INC_DIR)/*.h)


# src files
SRC = $(wildcard *.cpp) $(wildcard $(KERN_DIR)/*.cpp) $(wildcard $(CMN_DIR)/*.cpp)

# object files
OBJ = $(SRC:.cpp=.o)

all: $(TARGET)
    
clean:
    @rm -rf $(OBJ)
    @rm -rf $(TARGET)
    @echo "Cleaned..."
    
%.o: %.cpp $(HEADERS)
    $(CXX) $(CXXFLAGS) -c -o $@ $<

$(TARGET): $(OBJ)
    $(CXX) $(CXXFLAGS) $^ -o $@```
1
you need to install x32 version of standard library - StPiere
I am sorry if it is a stupid question, but how do I do that? I thought that was what gcc-multilib was. - Daniel123643
it depends on the os. on ubuntu try to search with apt-cache search libstdc++ | grep 386 or apt-cache search libstdc++ | grep 686 - StPiere
Yes hi @StPiere sry for late reply. I did as you suggested and added the x32 library from the grep. It did move me past the "cannot find lib" issues. Now Ive encountered a new problem where im getting error messages of the type "architecture of input file is incompatible with the i386 output". It is progress though and thanks for your help. - Daniel123643

1 Answers

1
votes

That's easy, just install the 32-bit development libraries

$ sudo apt update
$ sudo apt install gcc-multilib g++-multilib