简体   繁体   中英

How do I compile a c++ program into a 32-bit executable instead of 64-bit

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 $@```

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM