Thread: Why vc++ link can not find function which is built in the same project?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    42

    Why vc++ link can not find function which is built in the same project?

    Hi there,

    When I try to build the executable, the error is as the following:

    iis.obj : error LNK2001: unresolved external symbol "int __cdecl lm(int,char *)" (?lm@@YAHHPAD@Z)
    Debug/iis.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    The function is defined in the file buildd.c
    Code:
    //buildd.c
    #include <stdio.h>
    #include "buildd.h"
    
    int __cdecl lm(int i,char * filename)
    {
    	return i + strlen(filename);
    }
    
    file buildd.h
    
    #include "StdAfx.h"
    
    int __cdecl lm(int i,char * filename);
    and in iis.cpp, the code invoking the function lm is located in the body of int APIENTRY WinMain, which is:

    inm = lm(10,ryDict);

    Why the vc++ link can not find the function lm, which is built in the same project?

    Thanks,
    Last edited by wow; 12-29-2005 at 07:42 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > buildd.c
    Goto project settings, and add this source file to the list of source files in the project.
    So you should have
    buildd.c
    iis.cpp

    2. Do you really want to mix C and C++?
    Is there any particular reason why one of them needs to be in C ?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Oh, certainly I add these files into project through Project "Add to Project" before I posted, and so I post the issue.

    I even use the following link command. It still does not work
    Code:
            link -debug:full -debugtype:cv /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE /
    RELEASE /NOLOGO -subsystem:windows,4.0   iis.obj builddict.obj iis.res libc.lib
    oldnames.lib kernel32.lib  ws2_32.lib mswsock.lib advapi32.lib user32.lib gdi32.
    lib comdlg32.lib winspool.lib version.lib comctl32.lib shell32.lib  -out:is.exe
    
    iis.obj : error LNK2001: unresolved external symbol "int __cdecl lm(int,char *)"
     (?lm@@YAHHPAD@Z)
    is.exe : fatal error LNK1120: 1 unresolved externals
    NMAKE : fatal error U1077: 'link' : return code '0x460'
    Stop.
    Second, I have lot other codes in c. You can see I simplify the code to try it out.


    Thanks,
    Last edited by wow; 12-29-2005 at 10:29 AM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Thanks, it works.

    Happy new year to every one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM