Re: Link errors

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Paul G. Tobey [eMVP] (ptobey)
Date: 09/02/04


Date: Thu, 2 Sep 2004 14:44:36 -0700

C code *compiled for Windows CE*, not for the x86 emulator, right?

No, that's not true. C++ decorates the function names of things that it
sees declared so that linking is type-safe. That is, C++ can distinguish
between

int X( int a );

and

int X( float b );

In fact, it *has* to be able to do this to allow function overloading. If
you have an external C function that you are trying to declare, you *must*
wrap it with extern 'C', or C++ will see the declaration, modify the name it
is expecting to find, and your link will fail.

Most well-designed C libraries will do the right thing and wrap their
declarations in the header files so that they can be used from either C or
C++, but maybe that's not the case here. You'd do that something like this:

#ifdef __cplusplus
extern 'C'
{
#endif

<declarations here>

#ifdef __cplusplus
}
#endif

If the header files for this library don't have that, we've found the
problem and you may want to do something like:

extern 'C'
{
    #include <libraryheaderfile.h>
}

rather than what you probably have:

#include <libraryheaderfile.h>

Paul T.

"Pat Young" <PatYoung@discussions.microsoft.com> wrote in message
news:B89F5797-A2CA-46B5-9C80-00CB860EFFB6@microsoft.com...
> The processor is Intel Celeron. The lib herder files are c code. The
> library
> is C code library for x86 processor.
>
> But I noiced that all exapmle code from the vendor are C code. I believe
> that eVC++ is used for C++ code. The test application that I created is
> C++
> code (.cpp). I thought that I could directly use the c library without
> any
> changes or adding any extra code for calling C library functions in C++.
> Is
> it true?
>
> Pat
>
> "Paul G. Tobey [eMVP]" wrote:
>
>> I'd say that the library doesn't contain the function you are looking for
>> if
>> case 1 didn't work. Are you compiling your code as C++ and is the
>> library a
>> C library? Maybe name mangling is the problem. This library *is* for
>> the
>> right processor, right?
>>
>> Paul T.
>>
>> "Pat Young" <PatYoung@discussions.microsoft.com> wrote in message
>> news:4C104D0C-0383-48B0-B9EA-F55E2FFA9A31@microsoft.com...
>> > It still got the link errors even though changes were made based on
>> > suggestions from both Michael and Paul. Below are some test cases I
>> > did:
>> >
>> > Case 1:
>> > Object/library modules:
>> > mil.lib
>> >
>> > Additional library path:
>> > C:\Program Files\MIL for WinCE\Mil\Lib
>> >
>> > Error
>> > WinCETest002.obj : error LNK2019: unresolved external symbol
>> > __imp__RemoteMappFree referenced in function _WinMain
>> >
>> >
>> > Case 2:
>> > Object/library modules:
>> > mil.lib
>> >
>> > Additional library path:
>> > "C:\Program Files\MIL for WinCE\Mil\Lib"
>> >
>> > Error
>> > LINK : fatal error LNK1104: cannot open file 'mil.lib'
>> >
>> > case 3:
>> > Object/library modules:
>> > C:\Program Files\MIL for WinCE\Mil\Lib\mil.lib
>> >
>> > Additional library path:
>> > "C:\Program Files\MIL for WinCE\Mil\Lib"
>> >
>> > Error
>> > LINK : fatal error LNK1104: cannot open file 'C:\Program.obj'
>> >
>> > Case 4:
>> > Object/library modules:
>> >
>> > Additional library path:
>> > "C:\Program Files\MIL for WinCE\Mil\Lib\mil.lib"
>> >
>> > Error
>> > LINK : fatal error LNK1104: cannot open file 'Files\MIL.obj'
>> >
>> > Case 5:
>> > Object/library modules:
>> >
>> > Additional library path:
>> > C:\Program Files\MIL for WinCE\Mil\Lib\mil.lib
>> >
>> > Error
>> > WinCETest002.obj : error LNK2019: unresolved external symbol
>> > __imp__RemoteMappFree referenced in function _WinMain
>> >
>> > Case 6:
>> > Object/library modules:
>> > C:\Program Files\MIL for WinCE\Mil\Lib\mil.lib
>> >
>> > Additional library path:
>> >
>> > Error
>> > LINK : fatal error LNK1104: cannot open file 'C:\Program.obj'
>> >
>> > Case 7:
>> > Object/library modules:
>> > "C:\Program Files\MIL for WinCE\Mil\Lib\mil.lib"
>> >
>> > Additional library path:
>> > "C:\Program Files\MIL for WinCE\Mil\Lib"
>> >
>> > Error
>> > LINK : fatal error LNK1104: cannot open file 'Files\MIL.obj'
>> >
>> > Please see if there is anything else that I need to fix to build it
>> > correctly. Thanks.
>> >
>> > Pat
>> >
>> > "Paul G. Tobey [eMVP]" wrote:
>> >
>> >> And, although you specify the lib *path*, unless you specify the lib
>> >> *name*,
>> >> the library won't necessarily be added to the link. The library
>> >> developer
>> >> can arrange to make the library get included automatically, but it's
>> >> not
>> >> necessarily true that he did that...
>> >>
>> >> Paul T.
>> >>
>> >> "Michael J. Salamone [eMVP]" <mikesa#at#entrek#dot#com> wrote in
>> >> message
>> >> news:OLd6KuPkEHA.3456@TK2MSFTNGP12.phx.gbl...
>> >> > If specifying a full path, and it has spaces, you probably need to
>> >> > quote
>> >> > it.
>> >> >
>> >> > You shouldn't modify Library Directories for this. You should use,
>> >> > in
>> >> > Project Settings Link Tab, "dditional library path" (in the Input
>> >> > category).
>> >> > You probably need to quote it there, too. And, if you didn't quote
>> >> > it
>> >> > in
>> >> > Library Directories, that might be why it didn't find it in that
>> >> > case.
>> >> > In
>> >> > any case, undo whatever you did in Library Directories.
>> >> >
>> >> > I'm assuming your unresolved should be resolved by your mil.lib,
>> >> > correct?
>> >> > --
>> >> >
>> >> > Michael Salamone [eMVP]
>> >> > Entrek Software, Inc.
>> >> > www.entrek.com
>> >> >
>> >> >
>> >> >
>> >> > "Pat Young" <PatYoung@discussions.microsoft.com> wrote in message
>> >> > news:7D59BC16-3589-4C18-BE6A-743FD4689DF3@microsoft.com...
>> >> >> Hi,
>> >> >>
>> >> >> I am new to the eVC++. My development enviroment is the eVC++ 4.0
>> >> >> with
>> >> > sp2,
>> >> >> Windows XP and a third party device SDK.
>> >> >>
>> >> >> When I try to build a test application for a connected device, a
>> >> >> link
>> >> > error
>> >> >> 2019 "unresolved external symbol" occured even though the lib path
>> >> >> was
>> >> >> put
>> >> > on
>> >> >> the top of lib directories for the device platform.
>> >> >> Tools->Options...->Directories->Library files and the required
>> >> >> library
>> >> >> mil.lib was specified on the Object/library modules.
>> >> >>
>> >> >> Why did not the lib path take effect while linking?
>> >> >>
>> >> >> After the full path of the lib file was specified such as
>> >> >> C:\Program
>> >> >> Files\MIL for WinCE\Mil\Lib\mil.lib on the Object/library modules
>> >> >> and
>> >> > rebuilt
>> >> >> it, a new link error 1104 occured and followed by "cannot open file
>> >> >> 'C:\Program.obj'". What was wrong?
>> >> >>
>> >> >> Thanks in advance.
>> >> >>
>> >> >> Pat
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>



Relevant Pages

  • Re: Sources for functions like malloc()
    ... as long as you're looking for function declarations. ... They are already compiled and bundled into libraries of object code. ... but printf and malloc are about the last you may want to try. ... Try to find out if the source code of your libraries is available. ...
    (comp.lang.c)
  • Re: How to link a c library archieve (.a) in c++ project
    ... declare the functions in a header file created by me (and i'm almost ... certain that the declarations are correct). ... Otherwise the compiler will do name mangling on the ... You should always put the libraries at the end of the comand. ...
    (comp.os.linux.development.apps)
  • Re: Linking fails
    ... that would lead to a compilation ... function declarations. ... be found in the files being linked, including any libraries used. ... you do need to include the correct header, because that is the only place ...
    (comp.lang.c)
  • Re: [C] Libraries and headers
    ... > 1) Libraries are files containing one or more object files which include the ... > variables declarations, templates, constants and macros. ... I would only put global variables in header files if they were declared ... extern int MyGlobal; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Linker error - fooView.obj LNK2005: _IID_IProvideTaskPage already defined in fooDoc.obj
    ... declarations, one in the document and one in the view. ... multithreaded libraries would refer to symbols in the single-threaded and multithreaded ... Unless someone in the header files is ... Look for simple solutions first. ...
    (microsoft.public.vc.mfc)