473,396 Members | 1,877 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,396 software developers and data experts.

linking c files with a c++ program

Hi all,

To start with, I had 3 c files which I linked using bcc32 -

bcc32 1.c 2.c 3.c

Now I need to convert 1.c to 1.cpp. 1.cpp contains the main function.
The problem is that I now get "Undefined symbol" for any fuction found
in 2.c or 3.c that I try to call from 1.cpp.

I'm guessing the problem is to do with name mangling, but what should I
do exactly to resolve this problem?

Thanks for your help,

Barry.

Aug 17 '06 #1
3 1350
bg***@yahoo.com wrote:
To start with, I had 3 c files which I linked using bcc32 -

bcc32 1.c 2.c 3.c

Now I need to convert 1.c to 1.cpp. 1.cpp contains the main function.
The problem is that I now get "Undefined symbol" for any fuction
found in 2.c or 3.c that I try to call from 1.cpp.

I'm guessing the problem is to do with name mangling, but what should
I do exactly to resolve this problem?
What usually happens is that you change one file to compile with a C++
compiler, but forget to change the declaration of the functions from the
other (C) files to contain 'extern "C"'. The compiler thinks the have
C++ linkage and they don't.

There are two solutions: either change the declarations in the header
files to contain 'extern "C"' _if_ you compile with a C++ compiler:

---- some header included in both C and C++ sources:

#ifdef __cplusplus
extern "C" {
#endif

int foo(void);
void bar(int);

#ifdef __cplusplus
}
#endif

------------------------------

*or* compile _all_ files now using a C++ compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 17 '06 #2
In article <11**********************@m79g2000cwm.googlegroups .com>,
<bg***@yahoo.comwrote:
>To start with, I had 3 c files which I linked using bcc32 -

bcc32 1.c 2.c 3.c

Now I need to convert 1.c to 1.cpp. 1.cpp contains the main function.
The problem is that I now get "Undefined symbol" for any fuction found
in 2.c or 3.c that I try to call from 1.cpp.

I'm guessing the problem is to do with name mangling, but what should I
do exactly to resolve this problem?
This is one direct answer to your question:

http://www.comeaucomputing.com/techtalk/#externc

It's unclear whether it is necessary in your case though
because your do not say why are orchestrating your code this way,
so maybe there is some other alternative (compiling everything in C++
etc) if you give those details.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 17 '06 #3

Greg Comeau wrote:
In article <11**********************@m79g2000cwm.googlegroups .com>,
<bg***@yahoo.comwrote:
To start with, I had 3 c files which I linked using bcc32 -

bcc32 1.c 2.c 3.c

Now I need to convert 1.c to 1.cpp. 1.cpp contains the main function.
The problem is that I now get "Undefined symbol" for any fuction found
in 2.c or 3.c that I try to call from 1.cpp.

I'm guessing the problem is to do with name mangling, but what should I
do exactly to resolve this problem?

This is one direct answer to your question:

http://www.comeaucomputing.com/techtalk/#externc

It's unclear whether it is necessary in your case though
because your do not say why are orchestrating your code this way,
so maybe there is some other alternative (compiling everything in C++
etc) if you give those details.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Thanks for your help!

Aug 17 '06 #4

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

Similar topics

1
by: Jeff Hagelberg | last post by:
I'm trying to create a python module which can be used by a python interpreter embedded inside a fortran program I have. To do this, I first created python wrappers for all the functions in my...
1
by: Brian J. Ackermann | last post by:
Hi everybody, I'm new to c++, and I'm working on this simple little application, which ought to compile just fine, but I'm missing something. The program has 4 file, 2 headers, and 2 cpp files....
15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
3
by: Kevin Burton | last post by:
I am trying to use managed C++ but I am getting the following link errors: Metadata file 'D:\Projects\Visa\AddressVerification\AddressVerificat...
7
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
7
by: Salad | last post by:
I am converting an application from A97 to A2003. I have 2 tables created by another application as a Foxpro.dbf. The table has no index. The connect string in A97 is FoxPro...
0
by: fantasticamir | last post by:
I have a simple program using a couple of classes and it compiled successfully but while it is linking I have the following problem: g++ -Wall -lcu -lglu ACL2MDD.o Link.o Rule.o reachability.o ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.