I wish to write 64-bit assembly functions to use in some of my c++ projects, but I can't get it to work properly. I followed the instructions at http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system (http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system) and the command macro I used is "nasm $file -f elf -o $object". This works perfectly until I try to write 64-bit instructions. My two code files are
main.cpp
#include <iostream>
using namespace std;
extern "C" uint32_t test();
int main()
{
cout << hex << test() << endl;
cin.get();
return 0;
}
test.asm
global _test
_test:
mov eax, 0xdeadbeef
ret
This compiles and runs fine, but when I change the command macro to "nasm $file -f elf64 -o $object", the linker says that test.o is unrecognized file format. Is my command macro wrong for the 64-bit one or what? By the way, I am using code::blocks on windows.
Do you see the line:
nasm $file -f elf64 -o $object
or I guess when replaced with macros this line:
nasm test.asm -f elf64 -o test.o
in the build log?
This is the build log
mingw32-g++.exe -Wall -fexceptions -g -c "main.cpp" -o obj\Debug\main.o
nasm "test.asm" -f elf64 -o obj\Debug\test.o
mingw32-g++.exe -o "bin\Debug\Stress Test.exe" obj\Debug\main.o obj\Debug\test.o
obj\Debug\test.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
So yes it does appear in the build log.