Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to link obj's from c-source with obj's from c++-source

Reply
Thread Tools

How to link obj's from c-source with obj's from c++-source

 
 
Guido Belligoi
Guest
Posts: n/a
 
      10-19-2006
Hi,

I compiled 2 simple source-files with cl -c main.cpp and cl -c test.c.
test.c contains just a simple function, which is declared in test.h.
test.h is included in test.c and in main.cpp.
When I try to link the objects with link main.cpp test.c -outrog.exe
I get the error:
"main.obj : error LNK2019: unresolved external Symbol "int __cdecl
greater(int,int)" (?greater@@YAHHH@Z), called in function _main
prog.exe : fatal error LNK1120: 1 unresolved external Symbol"

What have I to do, to be able to link those objects together?

Guido Belligoi

 
Reply With Quote
 
 
 
 
Ivan Vecerina
Guest
Posts: n/a
 
      10-19-2006
"Guido Belligoi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
: Hi,
:
: I compiled 2 simple source-files with cl -c main.cpp and cl -c test.c.
: test.c contains just a simple function, which is declared in test.h.
: test.h is included in test.c and in main.cpp.
: When I try to link the objects with link main.cpp test.c -outrog.exe
: I get the error:
: "main.obj : error LNK2019: unresolved external Symbol "int __cdecl
: greater(int,int)" (?greater@@YAHHH@Z), called in function _main
: prog.exe : fatal error LNK1120: 1 unresolved external Symbol"
:
: What have I to do, to be able to link those objects together?

A: extern "C"


For headers that are to be included both from C and C++ sources,
it is common to surround all declarations with:

#ifdef __cplusplus
extern "C" {
#endif

int greater(int a, int b);

#ifdef __cplusplus
}
#endif


You could also include an originally C-only header with:
extern "C" {
#include "test.h"
}


IIRC it is also possible to declare an individual function
as extern C:

extern "C" int greater(int a, int b);



hth-Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com

 
Reply With Quote
 
 
 
 
Guido Belligoi
Guest
Posts: n/a
 
      10-19-2006

Ivan Vecerina schrieb:


a very helpfully answer!

Thank you for the fast reply - it works fine now!!!

Guido Belligoi

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is D-Link DSL-604T same as D-Link DSL-604+ ? norm Wireless Networking 6 11-18-2005 10:25 AM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
D-LINK DWL-AG650 doesn't work with WinXP - Zero Configuration Service (WZCSVC) / D-Link AirXpert nearly works Johannes Rosenstock Wireless Networking 0 08-27-2004 11:49 PM



Advertisments