[英]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.所以我正在尝试编译一个 c++ 程序并将可执行文件设置为 32 位而不是 64 位。 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.
我想在其上运行它的系统(使用程序模拟系统)是 32 位的,并且看到编译程序会产生 64 位 ELF 文件,我无法运行它们。 I have added the -m32 flag to the makefile and when compiling i get the following errors:
我在 makefile 中添加了 -m32 标志,编译时出现以下错误:
/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++ /usr/bin/ld:在搜索-lstdc++时跳过不兼容的/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so /usr/bin/ld:跳过不兼容的/usr/lib/gcc/x86_64- linux-gnu/5/libstdc++.a 搜索 -lstdc++ /usr/bin/ld 时:找不到 -lstdc++
when using sudo apt install -lstdc++ it simply says it cannot find the library.当使用 sudo apt install -lstdc++ 它只是说它找不到库。 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.
我在 windows 10 机器上的 Visual Studio 代码中使用远程 wsl 运行所有这些。 Ultimately I just want the compiled executables from this program to be 32-bit ELFs instead of 64-bit.
最终,我只希望从该程序编译的可执行文件是 32 位 ELF,而不是 64 位。
This is the make file The program im trying to compile is a benchmark suite located here https://github.com/alifahmed/hopscotch .这是 make 文件 我试图编译的程序是一个基准套件,位于https://github.com/alifahmed/hopscotch 。 This is the makefile otherwise located in /cpu/2_bandwidth:
这是 makefile,否则位于 /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很简单,只需安装32位开发库
$ sudo apt update
$ sudo apt install gcc-multilib g++-multilib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.