compiling
Recently I came across a package witch I want to use in my programs. The package consists of a header file (interface) and a *.c source code file (implementation). How can I use these files in my application? If I try to compile my application the compiler gives me this message: undefined reference. Darius Blaszijk
Re: compiling
On Sun, 11 Apr 1999, Darius Blaszijk wrote: # Recently I came across a package witch I want to use in my programs. The # package consists of a header file (interface) and a *.c source code file # (implementation). How can I use these files in my application? If I try # to compile my application the compiler gives me this message: undefined # reference. By your use of 'interface' and 'implementation' i'd say you've used modula-2 or pascal... and like those languages you must tell your C compiler to include the header file. Assuming the header is called foo.h and the source is called foo.c. Put them in the same directory as your c program (called bar.c in this example). in the top of bar.c put a line like this: (it goes along with the #include stdio.h and similar lines) #include "foo.h" this tells gcc to look in the current directory (which is what "" means. means 'look in standard include locations') then when you come to compile, type a command line like: gcc -Wall -o bar bar.c foo.c the -Wall just makes gcc really really picky about your code (a good thing). -o tells it what to call the executable (the first thing after the -o) and bar.c and foo.c are the sources to compile. You need to compile foo.c as well. If it was given as an object file (foo.o) then you'd do something slightly different ( gcc -Wall -c bar.c /* creates bar.o */ gcc -Wall -c foo.c /* creates foo.o */ gcc bar.o foo.o -o bar /* links them together into an executable called 'bar' */ ) -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: compiling
Hello! On Sun, 11 Apr 1999, Darius Blaszijk wrote: Recently I came across a package witch I want to use in my programs. The package consists of a header file (interface) and a *.c source code file (implementation). How can I use these files in my application? What you'll want to do probably is create a library and link it with your app. I forget exactly what you're supposed to do to create a static library (has something to do with the ar command), but it's like making a tar (in this case just ar) file of the object files... But if you just want to get it to work, try this: $ gcc app.c file1.c file2.c file3.c -o app Or something like that... I think that might work for you... Hopefully someone else will be able to be more help than I; my mind is numbed from doing homework for school tomorrow :) -Brett
Re: compiling
Hello again! :) Okay, well, I thought I was going to go back to my homework and forget about this, but of course I had to look up how to make a static library for our friend Darius here :) All right, what you want to do is compile each .c that you want in the library into an object file, .o You might do something like: % foreach i (*.c) gcc -c $i end or with Bash: $ for i in *.c do gcc -c $i done to get all those .o files... Okay, so now you make a static library from the .o files like this: $ ar r mylib.a file1.o file2.o file3.o $ ranlib mylib.a And now you've got a static library to use! $ gcc app.c mylib.a -o app You can delete an object file from your library with ar like this: $ ar d mylib.a badone.o Does that help... ? I hope so :) Have fun! -Brett
compiling with .so library files
hi, Im teaching myself to program in c and im having a real hard time figuring out how to get gcc to know how to find the functions it need from shared object files when linking. I'm currently working on the first simple gtk program that's in the gtk info page. when i try to compile I get the error: $ gcc -o gtktest gtktest.c /tmp/cca031931.o: In function `main': /tmp/cca031931.o(.text+0x1d): undefined reference to `gtk_init' /tmp/cca031931.o(.text+0x44): undefined reference to `gtk_window_new' /tmp/cca031931.o(.text+0x55): undefined reference to `gtk_widget_show' /tmp/cca031931.o(.text+0x5d): undefined reference to `gtk_main' Ive also been getting the same thing when trying to use math.h. After reading the info pages for gcc I tried using the -l and -L options to tell the linker where to find files. But when i did a -lgtk I ended up with more undefined refrences to things in gdk and when i added -lgdk even more. There has to be a better way to do this. Thanks jackson ___ ## / _ \ # D. Jackson Peacock # / /_\ \ # [EMAIL PROTECTED] # |___ __ | # ICQ 25755468 # | |_/ / # PO Box 2102# | __/ # Socorro, NM 87801 # --__/ / ## \/
Re: compiling with .so library files
On Sat, 3 Apr 1999, D. Jackson Peacock wrote: Hi. $ gcc -o gtktest gtktest.c You need to use $ gcc `gtk-config --cflags` `gtk-config --libs` gtktest.c -o gtktest Or you could write this as well: $ gcc -I/usr/local/lib/glib/include -I/usr/local/include \ -I/usr/X11R6/include -L/usr/local/lib -L/usr/X11R6/lib -lgtk \ -lgdk -lglib -lXext -lX11 -lm gtktest.c -o gtktest However, the first method is much easier to remember ofcourse. Good luck! Torbjørn S. Kristoffersen [EMAIL PROTECTED]
Re: Problem compiling LinuxDoom
Torbjørn Kristoffersen wrote: Now, there is another problem. Which is; when I compile the whole thing, it won't compile because it misses -lnsl. A library called SL(NSL?)? Anyone heard of it? Just remove the `-lnsl' from the Makefile. Similarly for `-lsocket' if it refers to that. libnsl is the `name service lookup' library. On some Unices it implements the gethostby* calls. With GNU libc, these are built into libc itself. -- Glynn Clements [EMAIL PROTECTED]
Problem compiling LinuxDoom
I have a problem with the same program which missed errnos.h. I solved the Errnos.h problem simply by making a symlink from /usr/include/errno.h to /usr/include/errnos.h. Now, there is another problem. Which is; when I compile the whole thing, it won't compile because it misses -lnsl. A library called SL(NSL?)? Anyone heard of it? Thanks, Torbjørn Kristoffersen [EMAIL PROTECTED]
Off Topic: Cross Compiling?
Can anyone point to me documentation on how to setup GCC and/or egcs to cross compile Solaris x86 binaries on my x86 Linux box? -- Edward Roper [EMAIL PROTECTED] 503.903.3729 WANfearhttp://www.WANfear.com/
Compiling code for linux
I have been using microshaft Visual C++ for my C++ class, but it sucks, big time. I really want to use linux, and I know a small deal about it, but I can't get a program to become an executable. I have tried before doing g++ source.cc and it would work, but then I would get an "a.out" file, which I believe to be an object file. I have tried looking at info on gcc, g++, object files and the linux doc project, but I have found nothing. I also get this error in emacs when trying to compile code by choosing compile from the menu. It then prompts me with make -k and I press return, then it gives me: cd ~/code/ make -k make: *** No Targets. Stop. Compilation exited abnormally with code 2 at Thu Sep 9 03:54:56 Sorry it sounds like a dumb question, but I have looked a bunch online. Thanks, Rob
Re: Compiling code for linux
Robert Linnemann wrote: I have been using microshaft Visual C++ for my C++ class, but it sucks, big time. I really want to use linux, and I know a small deal about it, but I can't get a program to become an executable. I have tried before doing g++ source.cc and it would work, but then I would get an "a.out" file, which I believe to be an object file. a.out is an executable. Typing `./a.out' will execute it. To specify a filename, use `-o', e.g. `g++ source.cc -o myprog'. I also get this error in emacs when trying to compile code by choosing compile from the menu. It then prompts me with make -k and I press return, then it gives me: cd ~/code/ make -k make: *** No Targets. Stop. To compile a program using make, you generally need a Makefile. It's possible to do without one if your program consists of a single file, e.g. `make -k source' will look for a file called source.something and then use the default rule for the extension. For a .cc file, it would use `g++ source.cc -o source'. More precisely, it would use $(CXX) -o source $(CPPFLAGS) $(CXXFLAGS) source.cc where CXX defaults to `g++', and CPPFLAGS and CXXFLAGS default to nothing. For more details, see the `make' info file (`C-h C-i make'). -- Glynn Clements [EMAIL PROTECTED]
Re: Compiling code for linux
Hello there! Just a real quick captured couple of commands and output that might help out, perhaps: cow:~/c$ cat foo.cc #include stdio.h main() { puts("Hello!"); } (I hit control-D here for EOF) (Yes, I know it's not C++, but I'm better at C :) cow:~/c$ g++ foo.cc (GCC or GNU C++ defaults to creating an excutable, a.out) cow:~/c$ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked, not stripped cow:~/c$ ./a.out Hello! (See, you can run it) (If you want to create an object file though...) cow:~/c$ g++ -c foo.cc (Use the -c option) cow:~/c$ file foo.o foo.o: ELF 32-bit LSB relocatable, Intel 80386, version 1, not stripped (And of course, if you want to create a file other than a.out, just use the -o option) cow:~/c$ g++ foo.cc -o happyhappyjoyjoy cow:~/c$ ./happyhappyjoyjoy Hello! So there you have it. FAR more easy to use than Micro$oft C++ once you learn the flags. I can't use Micro$oft's development products at all; all those menus, p! Anyway, hope this helps, have a nice day. :) And to the seasoned programmers who are laughing at me and how I write C and compiled with a C++ compiler here, well, I'm just trying to help out. :) -Brett
Errors compiling WindowMaker-0.14.1
errors full_errors Errors contains stderr, full_errors contains both stout and stderr (21) In short, it can't find pl_line_count, yy_scan_string, yy_delete_buffer, yyparse, or yyerror. What am I missing? I had to install bison and flex to get the ./Install script to work, but these look like missing libraries, since grepping for these identifiers turned up no definitions of these functions. Thanks for your help! ~Patrick errors full_errors