473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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 -out:prog.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

Oct 19 '06 #1
2 1993
"Guido Belligoi" <Do******@web.dewrote in message
news:11*********************@b28g2000cwb.googlegro 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 -out:prog.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

Oct 19 '06 #2

Ivan Vecerina schrieb:
a very helpfully answer!

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

Guido Belligoi

Oct 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Adams | last post by:
As well known I could specify the text color in the body tag like: <BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE> What I want to achieve now is that always (!) the text of the last visited...
6
by: Carla | last post by:
hi people, I have a little problem that I can't solve with css and i was wondering if you could help me. I have 4 links, I want that when I click/mouseover in the link 1, it turns to a color...
7
by: Shawn Windle | last post by:
----begin node.h-------- #ifndef NODE_H #define NODE_H #include <iostream> //NULL using namespace std; class node {
8
by: sudhirlko2001 | last post by:
How to swap two nodes of doubly Linklist
2
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
3
by: Eric | last post by:
Hello all, This is a C++ linker question. I'm trying to build an obj file, say foo.obj so that it is pre-linked with its dependencies. However I do not want to generated an executable right...
8
by: Bern McCarty | last post by:
We have a large mixed dll that I can never seem to get to link incrementally. Below is the console output. For simplicity I've eliminated some stuff that we normally do when we really link this...
7
by: Kurda Yon | last post by:
Hi everybody, I cannot understand the following thinks. The last line of the fillowing code produces a message about mistake (not a valid MySQL- Link resource): $link = mysql_connect(...
1
by: comp.lang.c++ | last post by:
NAME=Test PATH=../../IDE\WATCOM17\Bin LIB_PATH=../../IDE\WATCOM17\Lib INCLUDE_PATH=../../IDE\WATCOM17\Include BIN_PATH=../../Bin OBJS=$(NAME).obj LINK_FLAG= d all op inc op m op maxe=25 op...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.