Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking the first example with the instructions given doesn't work #1

Open
Hemaolle opened this issue May 18, 2021 · 3 comments
Open
Assignees
Labels
question Further information is requested

Comments

@Hemaolle
Copy link

I'm getting these errors with the command in the tutorial:

hello_world.obj : error LNK2001: unresolved external symbol ExitProcess
hello_world.obj : error LNK2001: unresolved external symbol printf
hello_world_basic.exe : fatal error LNK1120: 2 unresolved externals

This command worked for me:

link hello_world.obj /subsystem:console /out:hello_world_basic.exe kernel32.lib legacy_stdio_definitions.lib msvcrt.lib
  • There's no /entry:main
  • Added kernel32.lib legacy_stdio_definitions.lib msvcrt.lib

Also, I had to run this in x64 Native Tools Command Prompt for VS 2017, Developer Command Prompt for VS2017 suggested in the tutorial didn't work.

@sonictk sonictk self-assigned this Jul 27, 2021
@sonictk
Copy link
Owner

sonictk commented Jul 27, 2021

Hi @Hemaolle: thanks for the report! However, I'm slightly confused:

There's no /entry:main

Maybe it wasn't clear, but the Writing A Build Script section does cover this: https://sonictk.github.io/asm_tutorial/#hello,worldrevisted/writingabuildscript . The example also does specify /entry:main as well:

set BinLinkerFlagsMSVC=/subsystem:console /entry:main

Added kernel32.lib legacy_stdio_definitions.lib msvcrt.lib

This is also covered in the same section, and also specified in the example build script:

set CommonLinkerFlagsMSVC=%BinLinkerFlagsMSVC% /defaultlib:ucrt.lib /defaultlib:msvcrt.lib /defaultlib:legacy_stdio_definitions.lib /defaultlib:Kernel32.lib /defaultlib:Shell32.lib /nologo /incremental:no

Also, I had to run this in x64 Native Tools Command Prompt for VS 2017, Developer Command Prompt for VS2017 suggested in the tutorial didn't work.

That's very strange; what are you seeing when you try to run this in the developer command prompt? For all intents and purposes that should be calling vcvarsall.bat, which is similar to what is being done in the example build script (so that it doesn't require to be run from within a developer command prompt itself):

call "%vs2017installdir%\VC\Auxiliary\Build\vcvarsall.bat" x64

Let me know if something in the tutorial was otherwise unclear regarding the above!

@sonictk sonictk added the question Further information is requested label Jul 27, 2021
@Hemaolle
Copy link
Author

Hemaolle commented Jul 30, 2021

Ah, I suppose I could have been clearer about which section I was talking about. I didn't yet get to the build script part, this was about the "Hello, world" example: https://sonictk.github.io/asm_tutorial/#introduction/settingup/hello,world.

Hi @Hemaolle: thanks for the report! However, I'm slightly confused:

There's no /entry:main

Maybe it wasn't clear, but the Writing A Build Script section does cover this: https://sonictk.github.io/asm_tutorial/#hello,worldrevisted/writingabuildscript . The example also does specify /entry:main as well:

set BinLinkerFlagsMSVC=/subsystem:console /entry:main

To clarify, I had to remove part /entry:main from the example link command given in the "Hello, world" example which was

link hello_world.obj /subsystem:console /entry:main /out:hello_world_basic.exe

Added kernel32.lib legacy_stdio_definitions.lib msvcrt.lib

This is also covered in the same section, and also specified in the example build script:

set CommonLinkerFlagsMSVC=%BinLinkerFlagsMSVC% /defaultlib:ucrt.lib /defaultlib:msvcrt.lib /defaultlib:legacy_stdio_definitions.lib /defaultlib:Kernel32.lib /defaultlib:Shell32.lib /nologo /incremental:no

Maybe they should be added to the "Hello, world" example as well?

Also, I had to run this in x64 Native Tools Command Prompt for VS 2017, Developer Command Prompt for VS2017 suggested in the tutorial didn't work.

That's very strange; what are you seeing when you try to run this in the developer command prompt? For all intents and purposes that should be calling vcvarsall.bat, which is similar to what is being done in the example build script (so that it doesn't require to be run from within a developer command prompt itself):

call "%vs2017installdir%\VC\Auxiliary\Build\vcvarsall.bat" x64

Let me know if something in the tutorial was otherwise unclear regarding the above!

This is the output I get if I run the command that worked for me in x64 Native Tools Command Prompt for VS 2019 (I upgraded to VS 2019 since I tried this earlier, but it seems that the same problems exist in that version as before).

C:\Users\Leppaaho\Documents\Ohjelmointi\Assembler>link hello_world.obj /subsystem:console /out:hello_world_basic.exe kernel32.lib legacy_stdio_definitions.lib msvcrt.lib
Microsoft (R) Incremental Linker Version 14.29.30038.1
Copyright (C) Microsoft Corporation.  All rights reserved.

hello_world.obj : error LNK2001: unresolved external symbol ExitProcess
hello_world.obj : error LNK2001: unresolved external symbol printf
LINK : error LNK2001: unresolved external symbol mainCRTStartup
C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86\kernel32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\lib\x86\legacy_stdio_definitions.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\lib\x86\msvcrt.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
hello_world_basic.exe : fatal error LNK1120: 3 unresolved externals

Btw, when opening x64 Native Tools Command Prompt for VS 2019 it mentions that vcvarsall.bat script you mentioned

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.10.2
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

whereas Developer Command Prompt for VS 2019 doesn't, it only prints this part:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.10.2
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************

Let me know if something needs further clarification! 🙂

@sonictk
Copy link
Owner

sonictk commented Aug 5, 2021

Ah, I see. I think I can update the tutorial to add those instructions to the earlier part as well.

As for the developer command prompt; what's happening there is that you're getting the x86 version of the command prompt (which assumes you're developing for a 32-bit environment), to get the x64 version you want to launch the "x64 Native Tools Command Prompt for VS 2017" instead: https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line?view=msvc-160 I'll update the tutorial regarding this as well.

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants