473,407 Members | 2,314 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,407 software developers and data experts.

linking problem

Hello Groups,

I am facing this linking problem while using a c++ function in a C code.
I get this error....
gcc -o a.out cpp.o test.o
test.o(.text+0x29):test.c: undefined reference to `add'
Kindly tell me what is the problem.

Regards,

file "cpp.h" contains

#if __cplusplus
extern "C" {
#endif
extern int add(int a, int b);
#if __cplusplus
}
#endif

file "test.c" contains

#include<stdio.h>
#include"cpp.h"

main()
{
int a=1, b=2 ,c;

c=add(a,b);
printf("%d\n", c);
}

file "cpp.cc" contains

#include<iostream>
using namespace std;
int add(int a, int b)
{
int c;
c=a+b;
return c;
}

Makefile

a.out: cpp.o test.o
g++ -o a.out cpp.o test.o

test.o: test.c cpp.h
gcc -c test.c

cpp.o: cpp.cc
g++ -c cpp.cc


Jul 19 '05 #1
2 2863
Sameer wrote:
Hello Groups,

I am facing this linking problem while using a c++ function in a C
code. I get this error....
gcc -o a.out cpp.o test.o
test.o(.text+0x29):test.c: undefined reference to `add'
Kindly tell me what is the problem.

Regards,

file "cpp.h" contains

#if __cplusplus
#ifdef __cplusplus
extern "C" {
#endif
extern int add(int a, int b);
#if __cplusplus

#ifdef __cplusplus
}
#endif

file "test.c" contains

#include<stdio.h>
#include"cpp.h"

main()
int main()
{
int a=1, b=2 ,c;

c=add(a,b);
printf("%d\n", c);
}

file "cpp.cc" contains

#include<iostream>
using namespace std;


#ifdef __cplusplus
extern "C" {
#endif
int add(int a, int b)
{
int c;
c=a+b;
return c;
}
#ifdef __cplusplus
}
#endif

Makefile

a.out: cpp.o test.o
g++ -o a.out cpp.o test.o

test.o: test.c cpp.h
gcc -c test.c

cpp.o: cpp.cc
g++ -c cpp.cc


--
Attila aka WW
Jul 19 '05 #2

"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bl**********@newstree.wise.edt.ericsson.se...
Sameer wrote:
Hello Groups,

#ifdef __cplusplus
extern "C" {
#endif

--
Attila aka WW

Thanks Attila,
Sameer.
Jul 19 '05 #3

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

Similar topics

0
by: Wolfgang | last post by:
I have a problem with linking my CPP Code under a irix6 machine (sgi, UNIX). In my CPP code I use some Functions which are written in Python. So its a kind of CPP wrapper for my Python functions In...
27
by: Lee Phillips | last post by:
I believe it is universally accepted that decorating your website with images from someone else's, without permission, is rude and unethical, even if the images are in the public domain, because...
0
by: gasturbtec | last post by:
please help im new at access programming and i just got this project dropped in my lap because the old programmer quit. i've been doing ok so far but now i need to add code to an existing database...
18
by: Mark P | last post by:
I have a bit of vb code that uses Tables.Append to programatically link tables from Oracle and DB2 datasources. The problem I am having on some client machines is that the link will take anywhere...
17
by: Mitas Nikos | last post by:
I am trying to use the library conio2 and though I have managed with a few relatively simple examples when i try to compile a program which conio's function clrscr is not in main() i get an error...
1
by: buchalino | last post by:
Hi Guys, Please can someone help me, I am having a linking problem . I am writing a socket program, the problem is just the linking . I am using VC++ In the process of the problem, I...
5
by: news.microsoft.com | last post by:
We have recently upgraded from VS2002 to VS2005 and I'm having a problem with the linker always performing a full link even though nothing has changed. In searching the newsgroups I found that I...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
0
by: xieml2007 | last post by:
Dear Madam or Sir, I encountered one problem which is quite similiar to the discussions launched at the web site: http://www.thescripts.com/forum/thread280324.html
4
by: naveenmurthy | last post by:
Hello All, I have created a .mht file in following format. 1. The .mht file contains following htmls. a. MHTLinkingProblem.html b. Left.html c. Right.html d. Start.html
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.