简体   繁体   English

使用 g++ 编译 C++ 程序

[英]Compiling a C++ program with g++

I am having issues compiling my C++ program on g++ on Windows.我在 Windows 上的 g++ 上编译 C++ 程序时遇到问题。 My program is comprised of of the following files: one cpp file, two header files, and an asm file in MASM format.我的程序由以下文件组成:一个 cpp 文件、两个头文件和一个 MASM 格式的 asm 文件。 I tried using the following command to compile the x64 PE file:我尝试使用以下命令编译 x64 PE 文件:

g++ test.asm test.cpp -o test.exe

I am getting the following exception: file format not recognized;我收到以下异常:文件格式无法识别; treating as linker script.视为链接描述文件。

Could someone point me in the right direction?有人能指出我正确的方向吗? Thanks in advance!提前致谢!

There are different dialects of assembler.汇编程序有不同的方言。 MSVC uses MASM while GCC uses GAS. MSVC 使用 MASM,而 GCC 使用 GAS。

If your .asm file's format isn't understood by GCC try a different assembler like JWasm , UASM , SASM or NASM to compile it to COFF object file (eg jwasm -coff -win64 test.asm -Fo test.o ) and then use GCC to link your C++ program with it.如果.asm文件的格式不被 GCC 理解,请尝试使用不同的汇编程序,如JWasmUASMSASMNASM将其编译为 COFF 目标文件(例如jwasm -coff -win64 test.asm -Fo test.o )然后使用GCC 来链接你的 C++ 程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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