2

I have 4 .c files, one called main.c with main() but I get a linking error "undefined symbol _main in module c0.ASM." I am using TC.

I've searched on this site and the web, and found things like:

undefined symbol for architecture x86_64 in compiling C program

undefined symbol _main in module c0.ASM

but all of them seem to be gcc or c++ errors. The files are too large to paste here so I've uploaded them to mediafire.

#include <stdio.h>
#include <string.h>
#include "mpx.h"

int main()
{
return 0;
}

If I take out #include "MPX.H," I lose access to all shared variables defined in mpx.h, but if I get rid of all those too, program runs as it should (prints a statement and returns 1.

mpx.h:

http://www.mediafire.com/view/2pcxhwy9rwk9lls/MPX.H

compiler options: treat enums as ints, floating point emulation, generate underbars, debug info in objs, fast floating point

linker options: defalut libraries, "no stack" warning, case sensitive link, output - standard EXE

Community
  • 1
  • 1
  • why are you still using TC? Its like more then 10 years old. – Haris Nov 20 '15 at 05:57
  • @Haris I would say, 25. Seriously, I don't get the analogy, if you don't use a 25 year old PC, phone or car, why a compiler? – Sourav Ghosh Nov 20 '15 at 06:00
  • The program itself isn't the interesting information here. More interesting would be to know how you compile your program. Please share the compile commands. – M Oehm Nov 20 '15 at 06:01
  • I have to. It has special features that let me access early hardware on old ms-dos machines. – Augustine Tighe Nov 20 '15 at 06:02
  • i used TC back in 1989-90, you should seriously upgrade, there are many good, free compilers. E.g. http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/ – AndersK Nov 20 '15 at 06:02
  • Turbo C is still used for embedded development in many engineering shops. Crazy, but true. – selbie Nov 20 '15 at 06:10
  • Try to put the printf after the variable initializations. Try void main() as well to see if that help ? – DU Jiaen Nov 20 '15 at 06:18
  • @MOehm I have no idea what the commands are Im using Borland C++ 3.0 (4.0) on DOSBox – Augustine Tighe Nov 20 '15 at 06:20
  • @DUJiaen Just did that, same linker error. – Augustine Tighe Nov 20 '15 at 06:24
  • 1
    I suspect there may be an erroneous semi-colon or similar (unclosed comment, for example) in the `mpx.h` header file; that would certainly void the definition of `main()`, thus giving rise to the linker complaining about `_main` being an undefined symbol. Double check, and possibly (if not crazily long) post your header file as well). –  Nov 20 '15 at 06:31
  • Could there be something at the end of `"mpx.h"` that "eats" you `main` definition? (Clutching at straws here.) – M Oehm Nov 20 '15 at 06:32
  • @Evert Edited. Its pretty long so it was a hassle to try to format it to the post. – Augustine Tighe Nov 20 '15 at 06:39
  • @MOehm Check the edit. – Augustine Tighe Nov 20 '15 at 06:39
  • There's nothing obvious in `mpx.h` that I can see that might cause this. –  Nov 20 '15 at 06:42
  • Is there any way you can see which commands are run in the background when you build the project? Some logging level that can be increased. It'd be good to see if the linker does include all objects levels, and how the object files themselves are compiled (ah, I do love the command line for these kind of things). –  Nov 20 '15 at 06:44
  • @Evert edited again. That is all the info the Borland IDE gives me – Augustine Tighe Nov 20 '15 at 07:03
  • I see your edit with the compiler and linker options. We are, however, more curious *what* actually is compiled and linked: the actual commands that are being run behind the scenes. Any chance you can see those in some output window/log file? –  Nov 20 '15 at 07:04
  • @SouravGhosh not sure if that's an appropriate analogy - you wouldn't download a car, but you would download a compiler ! – M.M Nov 20 '15 at 07:19
  • 1
    This question needs to include a [MCVE](http://stackoverflow.com/help/mcve). Does the program `int main() { return 0; }` give the same error? If so, then the rest of the code is irrelevant. If not, then add in bits of the real code until the error starts happening. – M.M Nov 20 '15 at 07:20
  • Looks like the same question as [this one](http://stackoverflow.com/questions/26728897/undefined-symbol-main-in-module-c0-asm) which you dismiss as a "c++" question despite being a C question – M.M Nov 20 '15 at 07:22
  • @M.M but you _run_ both of them , don't you? ;) – Sourav Ghosh Nov 20 '15 at 07:24
  • @SouravGhosh Barely. Getting a 25 year old car or Turbo C to even start will be a challenge, and you probably won't get far without them breaking down. The difference is, when you are driving around in your 25 year old car, nobody is going to offer you a free Lamborghini, and if they do you would be a fool to refuse. When you are cruising around in Turbo C though, I'll offer you a free GCC. – Lundin Nov 20 '15 at 07:29
  • @Augustine Tighe Been 20 years but iirc this comes from having a broken project. The compiler probably can't even find the file with the code you posted. I think you might have to set up the path where the compiler should go looking. Otherwise, make a new project, add a clean main.c file with nothing but `int main (void) { return 0; }` in it, then take it from there. – Lundin Nov 20 '15 at 07:32
  • @M.M yes, int main() {return 0; } gives the same error. i am running on MS-DOS 7.1 or 2 at school and i'm running DOSBox 0.74 on my laptop. – Augustine Tighe Nov 20 '15 at 07:39
  • @AugustineTighe OK, can you update your question so it has the least possible code that still gives the error. Also it'd be good to show your compiler options (preferably as a commandline, but I can't remember if the TC build window shows this) – M.M Nov 20 '15 at 07:41
  • My best guess is this. You are compiling with Pascal calling convention. To verify you are using C go to `Options` menu / `Compiler` / `Entry/Exit Code...` and look at the `Calling Convention` option. You should be using _C_ but for some reason you might have _Pascal_ selected. – Michael Petch Nov 20 '15 at 08:17
  • @MichaelPetch It was C. Do you have any idea where I would find "background info" log file or some kind of compiler information other than what I have posted? – Augustine Tighe Nov 20 '15 at 08:25
  • @M.M if i remove #include "mpx.h" and remove everything other than int main() { return 0; } it runs fine, because it isnt linking with anything. somehow all the files arent getting linked together. And I have no idea how to find out any log information or compiler/linker info other than what i have already posted. – Augustine Tighe Nov 20 '15 at 08:34
  • @AugustineTighe you said earlier that `int main() { return 0; }` gives the error, now you say that it doesn't .. – M.M Nov 20 '15 at 08:35
  • renaming .c to .cpp would be a bad idea, it may cause the IDE to invoke the C++ compiler instead of the C compiler – M.M Nov 20 '15 at 08:36
  • In order to see how things are made, can you convert your PRJ (project file) to a make file using prj2make. Something like `prj2make file.prj file.mak` where `file` is the name of your project file. Updating your question with the `mak` file may help. – Michael Petch Nov 20 '15 at 08:45
  • As for the version information only thing I can think of are the first few lines of `tc /h` – Michael Petch Nov 20 '15 at 08:47
  • @M.M Sorry, I thought I was clear that it was a linking problem. Question is updated. – Augustine Tighe Nov 20 '15 at 08:51
  • Does the problem go away if you take out `#include "mpx.h"` ? (if so, update the question to say as much) – M.M Nov 20 '15 at 08:51
  • @M.M I've tried his MPX.H file here with a do nothing main and it does work. – Michael Petch Nov 20 '15 at 08:52
  • @MichaelPetch using the same compiler? – M.M Nov 20 '15 at 08:53
  • Well I am using Turbo C 3.00 (I have Installed Turbo C++ 3.0). The OP is using Borland C++ maybe not the same? Or maybe it is. when I run `tc /h` I get `Turbo C++ Version 3.0` – Michael Petch Nov 20 '15 at 08:53

0 Answers0