473,322 Members | 1,480 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.

Linker problem

20
I have created one header file calc.h and had saved it in INCLUDE directory that has following declaration:
#define NUMBER '0'
void push(double)
double pop(void)
int getop(char[])
int getch(void)
void ungetch(int)

And have created getop.c , stack.c , getch.c and saved in LIB directory.

In stack.c, pop and push has been defined and getch.c, getch() and ungetch() code is written.

I have created main.c program and has included the header file calc.h.
Compilation is not giving error but on executing it is giving linker error that _getop(), _pop() and _push() are undefined symbols.

PLZZZ i neeeed help to sort out this messss. I even try to save in BIN directory all the programs but does not help and I am not very aware of project creation in C++ right now.
Oct 28 '06 #1
5 2072
Banfa
9,065 Expert Mod 8TB
OK having functions called getch and ungetch is a bad idea because the C standard library (and yess C++ uses it too) defines functions with this name which is probably why you are getting link errors for those functions.

I would guess that you are doing something like this

cc main.c

In most compilers this will compile main.c to main.obj and then try to link main.obj into a program. However main.c does not contain all your code.

getop.c stack.c getch.c should not be in the lib directory, they are not part of any standard library they are part of your program code, they should be in the program source directory along with main.c.

Then you will be able to perform the following command

cc main.c getop.c stack.c getch.c

to compile and link all your code.
Oct 28 '06 #2
Shana
20
OK having functions called getch and ungetch is a bad idea because the C standard library (and yess C++ uses it too) defines functions with this name which is probably why you are getting link errors for those functions.

I would guess that you are doing something like this

cc main.c

In most compilers this will compile main.c to main.obj and then try to link main.obj into a program. However main.c does not contain all your code.

getop.c stack.c getch.c should not be in the lib directory, they are not part of any standard library they are part of your program code, they should be in the program source directory along with main.c.

Then you will be able to perform the following command

cc main.c getop.c stack.c getch.c

to compile and link all your code.

Actually I am trying to see the how functions outside the source program can be accessed be including header file created which has those function's declaration. Those functions should be defined some where else. I think This is how prinft scanf works!!!

If I have to include evry thing in the main.c program itself then wat is the use of creating my own header file? Plzzz I really need to know, I hav literally crushed my brain to make it work ......!!
Oct 29 '06 #3
Banfa
9,065 Expert Mod 8TB
I think This is how prinft scanf works!!!
Well you are wrong. You may not find the source code to printf and scanf (it isn't required but some toolsets ship it) on your system because they have already been compiled into the C runtime library. This is a library of binary objects.

You however have created 4 c files which call code in each other but are expecting the program to work by only compiling 1 of them.

If you have written the code it is probably worth compiling it so you need to compile and link all 4 files.

You could initially compile and link 3 of the files excluding main into your on private library and the compile main and link it with the library.

You do not have to include all the code in main.c but you do have to compile and link all your code files.
Oct 30 '06 #4
Shana
20
Well you are wrong. You may not find the source code to printf and scanf (it isn't required but some toolsets ship it) on your system because they have already been compiled into the C runtime library. This is a library of binary objects.

You however have created 4 c files which call code in each other but are expecting the program to work by only compiling 1 of them.

If you have written the code it is probably worth compiling it so you need to compile and link all 4 files.

You could initially compile and link 3 of the files excluding main into your on private library and the compile main and link it with the library.

You do not have to include all the code in main.c but you do have to compile and link all your code files.
Thanks for knowledge about printf and scanf. I have complied all files separately and is not giving me any error but yes when I try to run main.c file not compile as compilation is not giving me error, it is giving linker error. I can send u an entire program code as an attachment if u allow me to send u message.
Oct 31 '06 #5
Banfa
9,065 Expert Mod 8TB
Don't send the code, post the errors and the command lines you are using.
Oct 31 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: haplotype | last post by:
I have designed a package with several files, which is listed bellow base.cpp & base.hpp - define the template class base tree.cpp & tree.hpp - define the class tree derived from base<int>...
3
by: Georg | last post by:
Hello, I must be doing something wrong, but I don't get it: - compile gcc -c -O -Iinc src/hello.c -o obj/hello.o gcc -c -O -Iinc src/msg_1.c -o obj/msg_1.o gcc -c -O -Iinc src/msg_2.c -o...
2
by: Joske | last post by:
Hi, I'm having a similar problem as Scott. A static library with managed C++ functions fails to link in. See http://groups.google.be/groups?q=managed+C%2B%...
4
by: Saran | last post by:
Hi All, I'm getting the following linker error when I try to build a library. nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcw.lib(appcore.obj) : error...
3
by: Steve Baer | last post by:
I recently read your whitepaper under the "extremely long link times" post and have a question that I was hoping you could answer. My question is based on the following paragraph: Directives...
9
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but...
3
by: ralphsieminsky | last post by:
A project compiles fine under VS 2005 RC without the /clr option. However, when /clr is turned on several errors appear: - A symbol exported from a DLL is not found by another DLL referencing...
1
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
1
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- ...
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...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.