News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Unable to get x86-64 nasm to work

Started by killer13666, July 03, 2015, 06:42:13 PM

Previous topic - Next topic

killer13666

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 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.

scarphin

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?

killer13666

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.

scarphin

Does the file 'obj\Debug\test.o' exists? If it does then this is not a codeblocks issue as the linker says it's not recognized. If it doesn't then the quotes around the file names might be the problem, I don't have those in my build log. Try getting it work in command line (cmd.exe?) maybe by trying to remove the quotes first.

killer13666

Yes, the 'obj\Debug\test.o' does exist, I checked since I thought that might have been the problem as well. I will try it from the command line. The build log has always showed the quotes for me, so I don't know. Though when the command macro is set for 32-bit code, the build log shows the quotes as well.

killer13666

No, it does not work. I get the same error as before, that it is of an unsupported file type. Any ideas as to why this is doing this?

scarphin

Wrong forum to look for an answer to that as it's against the forum rules, try your tool's forum.