Click here to Skip to main content
15,664,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the assembly:
    extern  printf
    global  hello
    section .text
    push    message
    call    printf
    add     esp, 8
    section .data
    db      'Hello, World', 10, 0

And calling:
nasm -f win64 hello.asm

Works fine, but the linking to the C file doesn't:
gcc main.c hello.obj -o hello.exe

It gives me:
hello.obj:hello.asm:(.text+0x1): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.data'
collect2.exe: error: ld returned 1 exit status

This is the C file:
#include <stdio.h>
void hello();

int main() {
  return 0;

What I have tried:

I have tried keeping the "message" thing in the .text section, .rodata, and now .data. They all say this. I also tried nasm -f win32 but at linking it said it didn't support something with i386.
Updated 24-Nov-22 5:53am

Try this :
db      'Hello, World', 12, 0
I am guessing the problem is the string is twelve characters long, not ten.
Share this answer
Richard MacCutchan 24-Nov-22 11:44am    
The 10 (0x0A) at the end is a newline character, the zero is the end of the string.
It looks like you have created a 64-bit object module from the assembly code. And you hve created a 32-bit module from the C code. When you try to link the two the addresses in the assembly portion are too long. Change the assembler to generate 32-bit code, or the compiler to generate 64-bit.
Share this answer
CodeSie Programming 24-Nov-22 12:00pm    
I'll try this, thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900