473,395 Members | 1,688 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,395 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 1670
> 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.