Author Topic: Visual C++ 2005 Express linker issue  (Read 11010 times)

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Visual C++ 2005 Express linker issue
« on: November 03, 2011, 02:16:17 am »
Hello, I do WinXP SP3, and I've just started trying the VC++ 2005 Express compiler (in CodeBlocks of cours) to compile some of my sdl programs.  I've looked around online including here, but have been unsuccessful in dealing with the following linker error somehow:

sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError|

there are 8 other ones including fgetc and fopen.  Here are the other facts:

In compiler settings:  checked "Multi-threaded dll debug runtime library"

In compiler settings -> Linker Settings ->

kernel32.lib
user32.lib
gdi32.lib

(also were some others which i took out to see what would happen and the error is the same)

In compiler settings -> Linker Settings -> Other Settings:

/NODEFAULTLIB:msvcrt
/SUBSYSTEM:CONSOLE

In compiler settings -> Search Directories I have the compiler, linker and resource directories copied with copy/paste, verbatim, to the

c:\...vc\include, \lib

and c:\...platform sdk\include, \lib also.

for some reason, I'm at a loss...so thanks in advance for any and all replies! -B
« Last Edit: November 03, 2011, 02:17:54 am by bala_48225 »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Visual C++ 2005 Express linker issue
« Reply #1 on: November 03, 2011, 03:04:35 am »
Does the standard "Hello world" program compile with your current setup?
Code
#include <iostream>

int main()
{
    std::cout << "Hello world";
    return 0;
}

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Visual C++ 2005 Express linker issue
« Reply #2 on: November 03, 2011, 03:12:48 am »
yes it does, though it gives some warnings about exception handling:

C:\Program Files\Microsoft Visual C++ 2005 Express\VC\include\xlocnum|130|warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc|

that didn't happen with the sdl project and no biggie from where I'm sitting, but that's full disclosure.
« Last Edit: November 03, 2011, 03:15:49 am by bala_48225 »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Visual C++ 2005 Express linker issue
« Reply #3 on: November 03, 2011, 03:40:41 am »
OK - just testing for easy problems first (like improper compiler setup) :).

Have you tried using the Code::Blocks SDL project template?

The page Using SDL with Code::Blocks is for a different compiler (minGW), but you could check to see if there is something that is applicable to you.

Could you try compiling with full command line logging (when posting here, use code tags so that it is readable).


kernel32.lib
user32.lib
gdi32.lib
As a note, it is generally unnecessary to add the .lib file extensions (although it should not harm anything... I think).

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Visual C++ 2005 Express linker issue
« Reply #4 on: November 03, 2011, 02:50:21 pm »
Here is the full command line log:

Code
||=== ExtraLife, Debug ===|
LINK||warning LNK4044: unrecognized option '/EHsc'; ignored|
sprig.lib(d000017.o)||warning LNK4078: multiple '.text' sections found with different attributes (E0300020)|
sdlmain.lib(SDL_win32_main.obj)||warning LNK4217: locally defined symbol _isspace imported in function _ParseCommandLine|
sdlmain.lib(SDL_win32_main.obj)||warning LNK4217: locally defined symbol ___iob_func imported in function _ShowError|
sdlmain.lib(SDL_win32_main.obj)||warning LNK4217: locally defined symbol _fclose imported in function _cleanup_output|
sdlmain.lib(SDL_win32_main.obj)||warning LNK4217: locally defined symbol _exit imported in function _main|
sdlmain.lib(SDL_win32_main.obj)||warning LNK4217: locally defined symbol _atoi imported in function _WinMain@16|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__remove referenced in function _cleanup_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__fopen referenced in function _cleanup_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__fgetc referenced in function _cleanup_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__setbuf referenced in function _redirect_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__setvbuf referenced in function _redirect_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__freopen referenced in function _redirect_output|
sdlmain.lib(SDL_win32_main.obj)||error LNK2019: unresolved external symbol __imp__strrchr referenced in function _main|
bin\Debug\ExtraLife.exe||fatal error LNK1120: 8 unresolved externals|
||=== Build finished: 9 errors, 7 warnings ===|

and btw, here are the linker settings for the project:

sdl.lib
sdlmain.lib
sprig.lib
 
I took the .lib extension off of them all (project and compiler settings), but the errors are the same.

Edit:  Unbelievable!  I added #include <cstdio> to the main.cpp file and it now links!  (fopen is in stdio.h), however it crashes once it runs.


« Last Edit: November 03, 2011, 03:05:57 pm by bala_48225 »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Visual C++ 2005 Express linker issue
« Reply #5 on: November 03, 2011, 02:56:09 pm »
Why are you using this option; you are telling it NOT to use the normal C Library; why do you think you are getting C Library linking errors. They are likely related. Edit: This is an educated guess from a non Visual C/C++ programmer.

Code
/NODEFAULTLIB:msvcrt

Tim S.
« Last Edit: November 03, 2011, 03:24:24 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Visual C++ 2005 Express linker issue
« Reply #6 on: November 03, 2011, 07:46:31 pm »
Code
/NODEFAULTLIB:msvcrt
is required because msvcrt conflicts with some other libraries.  

Ok, I got it to work by using the suggestion by Alpha to try the code:blocks regular sdl project template with the few necessary modifications (no sdl.dll, just sdl.lib), then from there once I got a program running I added the other sdl add-on libraries and everything worked fine.  Thanx for the feedback to both.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Visual C++ 2005 Express linker issue
« Reply #7 on: November 03, 2011, 07:57:28 pm »
Keep in mind that the no default lib is a hack, and mixing libraries from different compilers 2005/2008/2010 (sp-s included) will break sooner or later.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Visual C++ 2005 Express linker issue
« Reply #8 on: November 03, 2011, 10:58:39 pm »
To Obfuscated:  why would the libraries be from different years?  :? I would imagine they're all from 2005.  Are you suggesting that the best thing is to use the full compiler rather than express version because the hack may be unstable in the long run?   Lastly, what does (sp-s) mean?

In general:  I was able to get the original project to work by making sure everything was the same in the compiler and debugger options as in the sdl project template version that I modified earlier. :)
« Last Edit: November 03, 2011, 11:03:29 pm by bala_48225 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Visual C++ 2005 Express linker issue
« Reply #9 on: November 04, 2011, 12:19:50 am »
I said that if you need to ignore the msvcrt library you have a configuration problem. You're mixing runtime libraries and you'll get some strange problems sooner or later.
You should build your project without this options to be on the safe side.

sp= service packs... they are different and uncompatible, as I hope you know.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline bala_48225

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Visual C++ 2005 Express linker issue
« Reply #10 on: November 07, 2011, 05:09:46 am »
Yes that's true, thanks for the heads up.  I'm only going to use that compiler for "level 4 warning parties".  :)

Edit 11-21-11:  Actually, all you have to do is click Help (in the Visual C++ IDE) and it will show you which libraries to ignore.  Then I guess add the linker command to ignore them in Code:Blocks when you compile/link.  By now I'm using the Visual C++ 2008 Express compiler.  I'll report back if it crashes on someone else's computer.
« Last Edit: November 22, 2011, 04:08:29 am by bala_48225 »