Code::Blocks Forums

User forums => Help => Topic started by: killer13666 on July 03, 2015, 06:42:13 pm

Title: Unable to get x86-64 nasm to work
Post by: killer13666 on July 03, 2015, 06:42:13 pm
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

Code
#include <iostream>

using namespace std;
extern "C" uint32_t test();

int main()
{
    cout << hex << test() << endl;
    cin.get();
    return 0;
}

test.asm

Code
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.
Title: Re: Unable to get x86-64 nasm to work
Post by: scarphin on July 03, 2015, 06:57:35 pm
Do you see the line:
Code
nasm $file -f elf64 -o $object
or I guess when replaced with macros this line:
Code
nasm test.asm -f elf64 -o test.o
in the build log?
Title: Re: Unable to get x86-64 nasm to work
Post by: killer13666 on July 03, 2015, 07:08:21 pm
This is the build log
Code
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.
Title: Re: Unable to get x86-64 nasm to work
Post by: scarphin on July 03, 2015, 11:25:53 pm
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.
Title: Re: Unable to get x86-64 nasm to work
Post by: killer13666 on July 03, 2015, 11:36:22 pm
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.
Title: Re: Unable to get x86-64 nasm to work
Post by: killer13666 on July 04, 2015, 04:11:54 am
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?
Title: Re: Unable to get x86-64 nasm to work
Post by: scarphin on July 04, 2015, 04:29:36 am
Wrong forum to look for an answer to that as it's against the forum rules, try your tool's forum.