472,969 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to compile using library

Hello

I'm new in C, And I want to compile program which use extern function.
How to do it because I always got error.
Undefined first referenced
symbol in file
greet /tmp/cchAXHfp.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

first I did "gcc -G -o libgreet.so greet.c" and it is ok.
Later I tried:
gcc -G -lgreet mix.c
gcc -L/local/data02/app/repapp/test/gp
-I/local/data02/app/repapp/test/gp mix.c
gcc -L/local/data02/app/repapp/test/gp mix.c

And always I got error.

Thx
Robert

bash-2.05$ cat greet.h
char *greet();

bash-2.05$ cat greet.c
#include "greet.h"

char *greet() {
return ((char *) "Hello!");
}
bash-2.05$ cat mix.c
#include <stdio.h>
extern char *greet();
int main() {
char *greeting = greet();
printf ("aa\n");
return (0);
}

Dec 13 '05 #1
1 1657
> I'm new in C, And I want to compile program which use extern function.
How to do it because I always got error.
Undefined first referenced
symbol in file
greet /tmp/cchAXHfp.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

first I did "gcc -G -o libgreet.so greet.c" and it is ok.
Later I tried:
gcc -G -lgreet mix.c
gcc -L/local/data02/app/repapp/test/gp
-I/local/data02/app/repapp/test/gp mix.c
gcc -L/local/data02/app/repapp/test/gp mix.c


<-- snip code -->

Simply linking both files to one executable :

$ gcc -c greet.c -o greet.o # compile file 1
$ gcc -c mix.c -o mix.o # compile file 2
$ gcc mix.o greet.o -o greet # link both object files into binary
$ ./greet # run binary

--
:wq
^X^Cy^K^X^C^C^C^C
Dec 13 '05 #2

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

Similar topics

1
by: David Swedish | last post by:
Hi all! I have made a C++ program that reads and interprets a TCL-script. I have actually succeeded to compile it in Visual Studio, but to avoid Windows I want to compile it on linux (using...
11
by: babuyama | last post by:
Hi, Is there a way to obtain library name at compile/preprocessor time? Assuming that the compilation unit, myfile.c is part of mylib.a, from myfile.c code at compile/preprocessor time, I would...
1
by: Raterus | last post by:
Hi, Is there a way I can see what commands VS.net is using to compile my asp.net projects? I'm sure its using the vbc/csc programs, but I'd love to see the command-line options it is using. ...
2
by: Shachar | last post by:
Hi All, When I'm trying to compile a class library with no web reference to x64 Release I Succeed. When trying to compile a class library with web reference to x64 Debug I Succeed. When...
0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
5
by: DFB | last post by:
I am the author of the ZLibNetWrapper project on SourceForge (located at zlibnetwrapper.sf.net). This project is a simple mixed-mode .NET wrapper around the ZLib compression library. The ZLib...
1
by: HugoScripts | last post by:
hi there, as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple...
5
by: sujeet | last post by:
Dear friends, I'm facing a strange problem... My Application is in Debug mode, and the third party static library i'm using is in release mode. When i compile and try to link my...
0
by: dot | last post by:
I spent a few headache filled days trying to use GMP on windows (XP pro) I finally got it to work and since I found little help on the Web I thought someone might find what i did useful. ...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.