new to visual C++ - "unresolved external symbol" linking errors

This is a discussion on new to visual C++ - "unresolved external symbol" linking errors within the C++ Programming forums, part of the General Programming Boards category; I've been programming for a while now, but almost exclusively in a linux environment. I've ported some code that I've ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    13

    new to visual C++ - "unresolved external symbol" linking errors

    I've been programming for a while now, but almost exclusively in a linux environment. I've ported some code that I've been using in linux to windows for a program that I'm writing, and it all compiles cleanly, but fails whiles linking.

    I'm very new to visual studio and visual c++, and I'm sure the linking problem i have is very simple to fix, but i can't get any results by fiddling around with it.

    The errors i'm getting are all "unresolved external symbol" errors, and they're all of functions that I've written and are in the source files that I've ported (I was having the same linking errors with winsock functions, but i just needed to add the ws2_32.lib as a dependency in the project). All the needed source files/headerfiles are added to my project.

    The code that I've ported is in a separate folder from my project's folder (which is just a simple test program for the ported code), and is also in a separate folder from their header files. I'm sure there's something else that needs to be done, but I'm not sure what or where in all of VS's menus. Any help would be really appreciated. Btw, I'm using Visual Studio .NET 2002

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Are you compiling them as a mix of C/C++ source files? If that was the case, then compilation would succeed but when linking there could be problems due to mangling of function names. What are the specific errors you are getting (cut and paste them if possible)? Also explain your directory structure; all the files (headers and source code) and where they are.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    Ah yeah, I forgot to mention... some are .c files, some are .cpp files.... they're all compatible with c++ (compiles and runs fine in g++. In fact, this program is a straight port of a test program that I used to test the my library in linux, with only very minor changes to get it to compile in windows).

    As for the directory structure, my project's directory is in a folder called My Documents/pmc_lib_test. All the files pertaining to this library that I've made is on a separate harddrive in a folder called pmc_libs, with the header files being in this directory and the source files being in pmc_libs/win32, pmc_libs/libs/nix, and pmc_libs/c++libs (/c++libs has a couple c++ wrapper classes for the library, which was written in C. The wrapper classes are also being used in the VS project).

    Also, not sure if this matters, but the include lines in the source files reference the header file's location relatively, (#include "../pmc.h", for example).

    Here is the cut and paste of the error log:
    Code:
        Linking...
    pmc_lib_test.obj : error LNK2019: unresolved external symbol "int __cdecl pmc_addtlv(struct pmcMsg *,unsigned short,unsigned short,void *)" (?pmc_addtlv@@YAHPAUpmcMsg@@GGPAX@Z) referenced in function _main
    pmc_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl pmc_addtlv(struct pmcMsg *,unsigned short,unsigned short,void *)" (?pmc_addtlv@@YAHPAUpmcMsg@@GGPAX@Z)
    pmc_lib_test.obj : error LNK2019: unresolved external symbol "struct pmcMsg * __cdecl pmc_createmsg(struct pmcMsg * *,unsigned short,unsigned short,unsigned short)" (?pmc_createmsg@@YAPAUpmcMsg@@PAPAU1@GGG@Z) referenced in function _main
    pmc_wrapper.obj : error LNK2001: unresolved external symbol "struct pmcMsg * __cdecl pmc_createmsg(struct pmcMsg * *,unsigned short,unsigned short,unsigned short)" (?pmc_createmsg@@YAPAUpmcMsg@@PAPAU1@GGG@Z)
    pmc_lib_test.obj : error LNK2019: unresolved external symbol "int __cdecl initwinsock(void)" (?initwinsock@@YAHXZ) referenced in function _main
    pmc_wrapper.obj : error LNK2019: unresolved external symbol "int __cdecl pmc_sendmsg(int,struct pmcMsg * *,char)" (?pmc_sendmsg@@YAHHPAPAUpmcMsg@@D@Z) referenced in function "public: int __thiscall CPMCMsg::Send(int)" (?Send@CPMCMsg@@QAEHH@Z)
    pmc_wrapper.obj : error LNK2019: unresolved external symbol "struct rpmcMsg * __cdecl pmc_recvmsg(int)" (?pmc_recvmsg@@YAPAUrpmcMsg@@H@Z) referenced in function "public: int __thiscall CPMCMsg::Recv(int)" (?Recv@CPMCMsg@@QAEHH@Z)
    .\Debug/pmc_lib_test.exe : fatal error LNK1120: 5 unresolved externals
    pmc_lib_test is the VS project, and pmc_wrapper is the source that contains the c++ wrapper classes.

    Here is my command line log:
    Code:
        Creating temporary file "C:\DOCUME~1\Matt\LOCALS~1\Temp\RSP000001.rsp" with contents
    [
    /OUT:".\Debug/pmc_lib_test.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:".\Debug/pmc_lib_test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:I386 odbc32.lib odbccp32.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
    "Debug\StdAfx.obj"
    "Debug\pmc_lib_test.obj"
    "Debug\pmc_w32.obj"
    "Debug\pmc_wrapper.obj"
    "Debug\srv_general_w32.obj"
    ]
    Creating command line "link.exe @C:\DOCUME~1\Matt\LOCALS~1\Temp\RSP000001.rsp"
    Any thoughts? Thanks for the help and quick reply
    Last edited by ubermensch; 04-13-2006 at 12:31 PM.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    Would this thread better fit in the windows programming forum? If so, could a moderator move it there please?

  5. #5
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    First of all it has nothing to do with the location of the headers because compling seems to work fine. The errors are linker errors.
    So I guess you have to link to some library that contain all these functions.
    Kurt

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,507
    > The code that I've ported is in a separate folder from my project's folder
    The "simple" answer is to just add all your "pmc library" source code to your test project so that everything compiles together.

    The "better" answer is to create a library project in your pmc library folder, compile that up as a library. Then in your test project, add appropriate links to "pmc.h" and "pmc.lib" in the same way that you did for winsock library.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    Alright, I thought that might be the case. Not a big deal, just a bit of a nuisance since the pmc source will still constantly need to be edited and recompiled. Thanks for the help

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    Well, the problem turned out to be the mangling of my C function names... all I had to do was export the C functions using

    Code:
    #ifdef __cplusplus
    extern "C" {  
    #endif	
    
    //Declare C functions here
    
    #ifdef __cplusplus
    }
    #endif
    in my header files, and it all compiles and links fine now. Stupid mistake =/ Hopefully this helps someone having the same problem, though

  9. #9
    Registered User
    Join Date
    Apr 2006
    Location
    London
    Posts
    3
    Hiya, not sure if you're still checking this thread, but i seem to be having virtually the same problem as you were. i tried what you suggested and it reduced the length of the linker errors, but they still show up except instead of looking like:

    Code:
    SCFfunction.obj : error LNK2001: unresolved external symbol "int __cdecl fwrite_scf(struct Scf *,struct _iobuf *)" (?fwrite_scf@@YAHPAUScf@@PAU_iobuf@@@Z)
    they have been shortened to:

    Code:
    SCFfunction.obj : error LNK2001: unresolved external symbol _fwrite_scf
    now it just looks like i've simply forgotten to include a library, but i didn't change anything else. did you see anything like that at all? it's probably just something really simple that's eluding me.

    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. multiple errors generated by socket headers
    By nocturna_gr in forum Windows Programming
    Replies: 5
    Last Post: 12-16-2007, 05:33 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 03:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21