Compiling error - sysdeps/i386/elf/start.S and undefined reference to main

176 views
Skip to first unread message

Richard Lund

unread,
Apr 5, 2012, 12:06:30 PM4/5/12
to Harbour Users
Hi.
I've spent about 90 minutes researching this and haven't found a
solution yet...

I'm running a 32bit SuSe and trying to compile my first Harbour
program into a Linux executable.
It compiles and runs perfectly fine without parameters, but it needs
the Harbour libraries to run, so it's not portable yet.

If I try:

hbmk test3 -static

I get the following error output:

Harbour 2.0.0 (Rev. -1)
Copyright (c) 1999-2010, http://www.harbour-project.org/
Compiling 'test3.prg'...
Lines 3, Functions/Procedures 1
Generating C source output to 'test3.c'... Done.
/usr/lib/gcc/i586-suse-linux/4.5/../../../crt1.o: In function
`_start':
/usr/src/packages/BUILD/glibc-2.11.2/csu/../sysdeps/i386/elf/start.S:
115: undefined reference to `main'
./test3.o: In function `HB_FUN_MAIN':
test3.c:(.text+0x17): undefined reference to `hb_vmExecute'
./test3.o: In function `hb_vm_SymbolInit_TEST3':
test3.c:(.text+0x4e): undefined reference to `hb_vmProcessSymbols'
./test3.o:(.data+0x38): undefined reference to `HB_FUN_QOUT'
/tmp/cc5KcKMd.o: In function `hb_lnk_SetDefault_build':
hb-build-root-24212.c:(.text+0x1e): undefined reference to
`hb_vmSetDefaultGT'
/tmp/cc5KcKMd.o: In function `_hb_lnk_ForceLink_build':
hb-build-root-24212.c:(.text+0x8): undefined reference to
`HB_FUN_HB_GT_STD'
collect2: ld returned 1 exit status

My code at this time is extremely simple and dumbed down:

function main()
? "All done."
return nil

From all I was able to gather, this error tends to show up either when
there is no function 'main' (which is clearly there in the .prg file)
or until the gcc compiler is run with the -g parameter.

I don't have any c experience at all, so all of what I found out was
learned on-the-fly and may be completely wrong.

Our Linux expert tried to uninstall and update the GCC compiler
without any change.

Also, the path in the second error line does not exist:
/usr/src/packages/BUILD is empty
I don't know if the file structure that the error is referring to is
created by the compiler or not.

So I figured I'd try to compile into a c file and compile that
separately using GCC - and that failed, too.
First off, I can't create a file test3.c - it always creates test3.o
instead (an object file, I guess). When I compile that with GCC, it
doesn't recognize it at all.
When I try to create a plain c file, the output says that it is
generating a file called test3.c, but then it doesn't show up
anywhere...

So yea, I tried a bunch of things, and I'm completely stumped at this
point.

I did notice on looking at the crt1.o file that it is hard-coded with
the paths sysdeps/i386/elf/start.S and /usr/src/packages/BUILD/
glibc-2.11.2/. There is no file start.S anywhere on the computer, and
as I said the BUILD folder is always empty, so I have no idea anymore
where to look for a solution here.

I hope someone here can help me out.

Thanks in advance!

Richard Lund

unread,
Apr 6, 2012, 4:52:42 PM4/6/12
to harbou...@googlegroups.com
Found a workaround myself.

I installed a copy of Debian (instead of OpenSuSe) and tried again, and this time I no longer encountered the error I reported.

Ran into a few issues of missing libraries and had to install gcc and various zlib or libz libraries after the compiler kept complaining about missing them:

    /usr/bin/ld: cannot find -l[xyz]

But I kept experimenting with the Synaptic Package Manager's search and installing libraries until it worked.

In the end, one more library was missing:

    /usr/bin/ld: cannot find -lz

That one required some Google work, but I found that the library I needed to install was zlib1g-dev, and after that was installed, it compiled normally!

Next hurdle was that when running the new executable on another computer, it required yet more libraries, so I told my compiler to include ALL static libraries - and it finally worked!

So now I have my working stand-alone portable executable, and hopefully someone else runs into the same issue (however unlikely it may be) and find help here.

Problem solved.

Reply all
Reply to author
Forward
0 new messages