473,387 Members | 3,033 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,387 software developers and data experts.

collect2: ld returned 1 exit status

Hi,

I am trying to link use a library created by me, and getting the
following error during linking:

$: sudo gcc -c mycode.c
$: sudo ar rc libmylib.a myfuncs.o
$: sudo runlib libmylib.a
$: gcc myfuncs.o -o mycode -L. -lmylib -lm
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
.../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status

What is the problem?

Thank you in advance
SB

Apr 22 '06 #1
5 55070
"bobrics" <bo*****@gmail.com> writes:
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'


Does your program have a main() function?
--
"Am I missing something?"
--Dan Pop
Apr 22 '06 #2
Yes, I do have a main function in mycode.c file
Ben Pfaff wrote:
"bobrics" <bo*****@gmail.com> writes:
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'


Does your program have a main() function?
--
"Am I missing something?"
--Dan Pop


Apr 22 '06 #3
I think I found my mistake. I am missing the mycode.c source filename
that contains main function.

$: gcc -o mycode -L. -lmylib myfuncs.o -lm
Should be:
$: gcc mycode.c -o mycode -L. -lmylib myfuncs.o -lm

I have another error, but that's due to global variable definition.
One of the functions that I have added into a library, modifies a
global variable that is defined in the main code (mycode.c). So, the
compiler complains that it's not defined inside mycuncs.c file. If I
will define it there, there'll be a double definition.
Is it still possible to do that (use globals and store functions that
modify these globals in a library) and how? I know it's a bad habit,
but there's some code that I need to adapt, but do not want to change
it.

Thank you
Ben Pfaff wrote:
"bobrics" <bo*****@gmail.com> writes:
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'


Does your program have a main() function?
--
"Am I missing something?"
--Dan Pop


Apr 22 '06 #4
So, I have modified the gcc line to:
$: sudo gcc mycode.c -o mycode -L. -lmylib myfuns.o
.... to specify mycode.c file. Below are the mycode.c and myfuncs.c
files. Here is the new error that I am getting:

$ sudo gcc mycode.c -o mycode -L. -lmylib myfuns.o
mycode.c: In function 'main':
mycode.c:7: warning: return type of 'main' is not 'int'
/tmp/ccgzNw0T.o: In function `main':
mycode.c:(.text+0x1d): undefined reference to `myfun1'
mycode.c:(.text+0x22): undefined reference to `myfun2'
collect2: ld returned 1 exit status

So, even though I am declaring the prototypes in mycode.c file as
extern functions, the compiler still complains.
AND here are my files.
---> mycode.c
#include <stdio.h>

extern void myfun1();
extern void myfun2();
void main() {
myfun1();
myfun2();
}
---> myfuncs.c
#include <stdio.h>

void fun1() {
printf("This is fun1()\n");
}

void fun2() {
printf("This is fun2()\n");
}





bobrics wrote:
Yes, I do have a main function in mycode.c file
Ben Pfaff wrote:
"bobrics" <bo*****@gmail.com> writes:
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'


Does your program have a main() function?
--
"Am I missing something?"
--Dan Pop


Apr 22 '06 #5
bobrics wrote:
I think I found my mistake. I am missing the mycode.c source filename
that contains main function.

$: gcc -o mycode -L. -lmylib myfuncs.o -lm
Should be:
$: gcc mycode.c -o mycode -L. -lmylib myfuncs.o -lm

I have another error, but that's due to global variable definition.
One of the functions that I have added into a library, modifies a
global variable that is defined in the main code (mycode.c). So, the
compiler complains that it's not defined inside mycuncs.c file. If I
will define it there, there'll be a double definition.
Is it still possible to do that (use globals and store functions that
modify these globals in a library) and how? I know it's a bad habit,
but there's some code that I need to adapt, but do not want to change
it.

Thank you
Ben Pfaff wrote:
"bobrics" <bo*****@gmail.com> writes:
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'

Does your program have a main() function?
--
"Am I missing something?"
--Dan Pop


Don't top post, and you can use the "extern" keyword before all other
definitions other than the first one, I think. It's been a long time
since I used multi-file variables, or even global-scope variables.
Apr 22 '06 #6

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

Similar topics

2
by: Sami Viitanen | last post by:
Hello, Is there a way to check if a command executed in ms-dos returns 0 (success) or greater than 0 (fail) ? In Unix the module commands.getstatusoutput returns exit status.. Thanks in...
1
by: user | last post by:
How can I get the exit status from a "popen2" pipe? For example, from child_stdout, child_stdin, child_stderr = popen2.popen3(command) how can I tell what the exit status it? Want to find out...
2
by: Ishwar Rattan | last post by:
Here is a piece code (according to blurb on os.wait, the lower order 7 bits of exit status of process should contain the signal number of signal that terminated the process..) and signal number...
3
by: learning_C++ | last post by:
Hi, When i tried to compile my code, there is an error: collect2: ld returned 1 exit status what is the reason causing this error? Thanks,,
3
by: John Williams | last post by:
VB .Net 2003, .Net Framework 1.1, Windows XP Pro SP1 I've written a console application which I run as a scheduled task. How do I return an exit status value (or string) from the application so...
2
by: Jeffrey W. Baker | last post by:
I just noticed something unexpected when using psql. I had written a shell script to bulk-load some hundreds of files into a database, and move each file to success/ or failure/ directories...
1
by: vermarajeev | last post by:
Hi guys, Can anyone tell me some link where I can get the exit status meaning. For example What does exit( 30 ) mean? Here what does 30 means?? exit(99) and so on... I want a...
2
by: Navaneet | last post by:
Hi, I am building a application on linux. I am getting an error which relates to undefined reference to a function. I had build same on other platform, no error comes. Here is whole error...
2
by: PAK11 | last post by:
Hello everyone I am having trouble figuring out what is wrong with my program. When I compile the message says "undefined reference to 'WinMain@16' collect2: Id returned 1 exit status". Im not sure...
5
by: Andrew Greensted | last post by:
Hi All, I've written a simple c program that reads stdin, adds highlighting to particular words and outputs the result to stdout. I invoke it as follows (where xil-highlight is my program): ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
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...

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.