Board index » cppbuilder » Linking C files and Converting to Fortran

Linking C files and Converting to Fortran

Hello. I'm using Builder 5 standard and I'm trying to compile C code
that was translated from Fortran using Cobalt Blue's For_C product. Each
tanslated file compiles, but the program will not link. I get the error:
[Linker Error] Unresolved external '_main' referenced from C:\PROGRAM
FILES\BORLAND\CBUILDER5\LIB\C0X32.OBJ. What I have found out so far is
that previous versions of Builder must have a the main function called
from a cpp file but this problem was supposed to be fixed by now. I was
wondering if you have are trying to compile a console application and is
it supposed to be C or C++? I found two articles about this problem at:
http://community.borland.com/article/0,1410,23055,00.html and at:
http://community.borland.com/article/0,1410,18809,00.html. I hope that
maybe we can find the solution to this problem.

Marcus McElhaney

 

Re:Linking C files and Converting to Fortran


Quote
> previous versions of Builder must have a the main
> function called from a cpp file but this problem was
> supposed to be fixed by now

Console mode programs start processing at the function main.  That is also
the case for the C and C++ language standards.  If you are building a
console mode program and do not have a function called main where processing
is expected to start, that is not a problem with the compiler.  It is a
problem with the code.

.  Ed

Re:Linking C files and Converting to Fortran


I'm sorry I should have been clearer. I have a main function in one of the c
files and that file does compile. The project just will not link. I get  the
error: [Linker Error] Unresolved external '_main' referenced from C:\PROGRAM
FILES\BORLAND\CBUILDER5\LIB\C0X32.OBJ    Thanks.

Marcus McElhaney

Quote
"Ed Mulroy [TeamB]" wrote:
> > previous versions of Builder must have a the main
> > function called from a cpp file but this problem was
> > supposed to be fixed by now

> Console mode programs start processing at the function main.  That is also
> the case for the C and C++ language standards.  If you are building a
> console mode program and do not have a function called main where processing
> is expected to start, that is not a problem with the compiler.  It is a
> problem with the code.

> .  Ed

Re:Linking C files and Converting to Fortran


No you do not have the 'main' function in what you linked or the linker
would have found it.  The function 'main' in both C and C++ has the public
symbol "_main", and that is the function the startup code (c0x32.obj here)
calls to start the program.  If you'd had two of them, the error would have
been different.

Look at the files that are specified in your project.  The one containing
main isn't in there.

.  Ed

Re:Linking C files and Converting to Fortran


If I'm understanding the Builder Interface correctly, if a file is listed in
the project manager under the executable, then the file is being linked into
the program. All the files in my project have c extentions and one of those
files listed in my project manager is the file containing my main function. All
the paths and directories are correct because if they were not then none of the
files would compile. I only have one of  them in my project. In short the file
containing my main function is in there. I've checked backwards and forwards to
make sure that the file is included to be linked. I've even tried to add it to
the project again and it still would not link. I thought that maybe because the
translated code does not return anything might be the reason why the linker
doesn't see it, so made it return 0, but the linker still gives the same error.
Thanks for trying to help. If you have any more ideas, please share. I know
everything  you are saying, Ed, is correct and I appreciate it. But I don't see
why it can't see the main function it's right there.

Marcus McElhaney

Quote
"Ed Mulroy [TeamB]" wrote:
> No you do not have the 'main' function in what you linked or the linker
> would have found it.  The function 'main' in both C and C++ has the public
> symbol "_main", and that is the function the startup code (c0x32.obj here)
> calls to start the program.  If you'd had two of them, the error would have
> been different.

> Look at the files that are specified in your project.  The one containing
> main isn't in there.

> .  Ed

Other Threads