“Undefined reference” when linking C code in Linux?

You have the -l options in the wrong place.

You have the -l options in the wrong place -llibrary -l library Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance> and is not recommended. ) It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified.

Thus, foo. O -lz bar. O searches library z after file foo.

O but before bar.o. If bar. O refers to functions in z, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

You haven't given enough information for a complete answer, but I think I know one of your problems: The functions open, read, write, close, etc. Have underscores in front of their names on Windows, but they do not on Linux (or any other Unix for that matter). The compiler should have warned you about that when you compiled the . C files -- if it didn't, turn on warnings!

Anyway, you're going to have to remove all those underscores. I would recommend a header file that does something like #ifdef _WIN32 #define open(p, f, m) _open(p, f, m) #define read(f, b, n) _read(f, b, n) #define write(f, b, n _write(f, b, n) #define close(f) _close(f) /* etc */ #endif and then use only the no-underscore names in your actual code. Also, -l options (such as -lm) must be placed after all object files.

It is unnecessary to specify -lc (and it may cause problems, under circumstances which are too arcane to go into here).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions