Can someone give me some pointers where im going wrong, im new to assembly, GCC, C, NASM, NASMW.
I cant get past this error when trying to make the object, is there something extra i need to install.
C:\test>nasmw -f win32 prog.asm -o prog.obj
prog.asm:12: error: symbol `_printf' undefined

Dani AI

Generated

In this thread reported an assembly-time error: the assembler flagged _printf as undefined. is correct that the assembler must be told when a symbol is provided by an external library, and correctly points out platform name-decoration differences. The assembled object must then be linked with a C runtime so the function address is resolved.

Common, practical steps that resolve this class of error:

nasm -f win32 prog.asm -o prog.obj
gcc prog.obj -o prog.exe

Using GCC (MinGW) to link is the simplest way on Windows because it pulls in the C runtime automatically. If using the Microsoft toolchain, include the appropriate import library when linking.

Pitfalls to watch for:

  • Target format and bitness must match the runtime. 32-bit object files use different name decoration (leading underscore) than 64-bit, so assemble with the right -f option.
  • If the symbol is used in data (for example storing a function pointer), the assembler tries to resolve it at assembly time and will require an explicit external declaration and a relocatable reference.
  • Respect the C calling convention for vararg functions (push args right-to-left; caller cleans the stack on 32-bit).

Quick diagnostics:

  • Produce an assembly listing or object symbol table to see unresolved names.
  • Use objdump -t prog.obj or the MSVC dumpbin /symbols equivalent to inspect symbols and confirm which names are unresolved.

These checks usually reveal whether the issue is a missing external declaration, a mismatched object format, or a linking step that omitted the C runtime.

Recommended Answers

All 2 Replies

_printf is not resolved until linked, therefore you have to make the complier aware of this.

extern  _printf

I haven't had any success using standard "C" libraires so I use wsprintf which is part of kernel32.lib

C library functions (like printf) are typically prefixed with an underscore. In in the object library it is actually named _printf.

If you plan to use them you must also link the library itself. How to do this varies between assemblers / linkers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.