Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. LNK2001, errno and messing with libraries

LNK2001, errno and messing with libraries

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlounge
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Janine
    wrote on last edited by
    #1

    Hello, I can't get rid of error LNK2001: unresolved external symbol _errno. I asked for help concerning this last week and got some answears, thanks a lot for them:rose: , but unfortunately they didn't help. So, at the moment the situation is like this. The starting point of my program is main() and it uses a library, that is written in C and supports MFC. The file where main is is a .c -file. Besides that file I have a few files for GUI, the library and a couple of .c -files written in C. I should use makefile, but I'm trying to get this working first with project/settings -options and then I'll export a makefile. I have set "Use MFC in a static library" from Project/Settings/General, "Multithreaded" from Project/Settings/C/C++/CodeGeneration/Use run-time library, "Automatic use of precompiled headers through header stdafx.h" from .../C/C++/Precompiled headers. I have also forced the program to be compiled with an option /TP. I also had to deny usage of two default libraries with linking options /nodefaultlib:"libc.lib" /nodefaultlib:"libcmt.lib", because they conflicted with the library licmtd.lib. The result is, that I get "LNK2001: unresolved external symbol _errno". The place where I get it from is inside the library written in C, that I'm using. If I used libc.lib and denied the usage of two others I would get 66 unresolved externals instead of errno and if I used only libcmt.lib, I would get 45 unresolved externals including errno. I have the source code of that library, but I can't modify it. In that file, where I get this error from header errno.h is included, but it is inside #ifndef _INCLUDE__STDC__. Could this be the reason why errno is unresolved? The calling convention that I'm using is __cdecl, from .../C/C++/CodeGeneration/Calling convention. I tried using stdcall, but I only got some more linking errors. I've also tried using extern "C" with all the headers written in C, and it didn't help. What I concluded, is that libc.lib includes the definition of errno, but libcmt.lib and libcmtd.lib don't. What should I do? Would making a dll help. -Janetta

    D 1 Reply Last reply
    0
    • J Janine

      Hello, I can't get rid of error LNK2001: unresolved external symbol _errno. I asked for help concerning this last week and got some answears, thanks a lot for them:rose: , but unfortunately they didn't help. So, at the moment the situation is like this. The starting point of my program is main() and it uses a library, that is written in C and supports MFC. The file where main is is a .c -file. Besides that file I have a few files for GUI, the library and a couple of .c -files written in C. I should use makefile, but I'm trying to get this working first with project/settings -options and then I'll export a makefile. I have set "Use MFC in a static library" from Project/Settings/General, "Multithreaded" from Project/Settings/C/C++/CodeGeneration/Use run-time library, "Automatic use of precompiled headers through header stdafx.h" from .../C/C++/Precompiled headers. I have also forced the program to be compiled with an option /TP. I also had to deny usage of two default libraries with linking options /nodefaultlib:"libc.lib" /nodefaultlib:"libcmt.lib", because they conflicted with the library licmtd.lib. The result is, that I get "LNK2001: unresolved external symbol _errno". The place where I get it from is inside the library written in C, that I'm using. If I used libc.lib and denied the usage of two others I would get 66 unresolved externals instead of errno and if I used only libcmt.lib, I would get 45 unresolved externals including errno. I have the source code of that library, but I can't modify it. In that file, where I get this error from header errno.h is included, but it is inside #ifndef _INCLUDE__STDC__. Could this be the reason why errno is unresolved? The calling convention that I'm using is __cdecl, from .../C/C++/CodeGeneration/Calling convention. I tried using stdcall, but I only got some more linking errors. I've also tried using extern "C" with all the headers written in C, and it didn't help. What I concluded, is that libc.lib includes the definition of errno, but libcmt.lib and libcmtd.lib don't. What should I do? Would making a dll help. -Janetta

      D Offline
      D Offline
      Daniel Lohmann
      wrote on last edited by
      #2

      As far as I can see the problem is, that the multithreaded versions of the CRT do not define errno, because it would not fit into a multithreaded environment, but you import a .lib that was linked against the single threaded CRT and therefore expects errno to be defined somewhere. (The MT version do not define it because using a single errno variable for multiple concurrent running threads is not a really good idea). You have to link all parts of your project (all .lib files you create on your own and the .exe) again exactly the same version of the CRT, so you got no linking conflicts. Using /nodefaultlib is only a "hack solution" and leads to problems like yours. -- Daniel Lohmann http://www.losoft.de

      J 1 Reply Last reply
      0
      • D Daniel Lohmann

        As far as I can see the problem is, that the multithreaded versions of the CRT do not define errno, because it would not fit into a multithreaded environment, but you import a .lib that was linked against the single threaded CRT and therefore expects errno to be defined somewhere. (The MT version do not define it because using a single errno variable for multiple concurrent running threads is not a really good idea). You have to link all parts of your project (all .lib files you create on your own and the .exe) again exactly the same version of the CRT, so you got no linking conflicts. Using /nodefaultlib is only a "hack solution" and leads to problems like yours. -- Daniel Lohmann http://www.losoft.de

        J Offline
        J Offline
        Janine
        wrote on last edited by
        #3

        Thanks a lot! It works now! It wasn't a big thing to do and now it seems obvious, but earlier it didn't. -Janetta

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups