简体   繁体   English

如何将 c++ 程序编译为 32 位可执行文件而不是 64 位

[英]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.

相关问题 为什么在 C++ 中编译 64 位时会出现 32 位溢出? - Why do I get a 32-bit overflow when compiling in 64-bit in C++? 在64位C ++程序中使用32位库 - Using 32-bit library in 64-bit C++ program 为什么我在 32 位 Mac OS X 系统上看到 C++ 中的 64 位指针? - Why do I see 64-bit pointers in C++ on my 32-bit Mac OS X system? 如何在64位Ubuntu 18.04上使用64位clang v8构建32位libc ++? - How do I build 32-bit libc++ with 64-bit clang v8 on 64-bit Ubuntu 18.04? 如何测量 32 位程序中 64 位进程的内存使用情况? - How can I measure memory usage of 64-bit process in 32-bit program ? "如何从 32 位 C++ 应用程序启动 64 位 Java 应用程序?" - How to start 64-bit Java application from 32-bit C++ application? 如何在64位机器上将C ++程序编译为64位? - How to compile a C++ program as 64-bit on 64-bit machine? 如何使Visual Studio 2012调用本机64位Visual C ++编译器而不是32位x64交叉编译器? - How to make Visual Studio 2012 call the native 64-bit Visual C++ compiler instead of the 32-bit x64 cross-compiler? 尝试(并且失败)在Windows 10上的64位Ubuntu上运行Hello World 32位C ++程序 - Trying (and failing) to run Hello World 32-bit C++ program on 64-bit Ubuntu on Windows 10 如何将混合(asm,C ++)源代码编译为32位程序? - How can I compile a hybrid (asm, C++) source code into a 32-bit program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM