|
From: Keith M. <kei...@us...> - 2010-11-25 10:40:23
|
On 25 November 2010 08:19, William Simpson wrote: > From: > > http://www.mingw.org/wiki/IncludePathHOWTO > http://www.mingw.org/wiki/SpecsFileHOWTO You should also look at: http://mingw.org/wiki/LibraryPathHOWTO > it seems I have a few options. > > Under djgpp I did as follows, for a library I wrote called rand. I > have djgpp\lib\src\rand\rand.c > I have the source rand.c, the header rand.h, and the makefile there. > In the makefile I have > rand: rand.c > gcc -c rand.c > ar rvs librand.a rand.o > del rand.o > move librand.a \djgpp\lib > copy rand.h \djgpp\include You should break this up, into separate build and install rules, (and for preference, also separate clean rules): rand: librand.a CC = gcc libdir = c:/djgpp/lib includedir = c:/djgpp/include %.o: %.c $(CC) -c $< rand.o: rand.c rand.h librand.a: rand.o # and any other objects you wish it to include del $@ ar rcvs $@ $^ install: copy librand.a $(libdir) copy rand.h $(includedir) clean: del *.o distclean: clean del *.a > Then subsequently I put #include "rand" ... The header file is rand.h, right? (That's what your makefile installed, in any case). Thus, you should use #include "rand.h", (if you want to be able to override the installed version with a local copy in the same directory in the including source), or #include <rand.h> to always use the installed copy from the compiler's include path. > ... at the top of any program that > uses it and put -lrand in my makefile when I compile it. You add -lrand *after* the list of object files, in the gcc command line in your makefile, at the point where you *link* the final executable. > First, I think that for mingw I need to put a "\" at the ends of the > lines like so: > rand: rand.c > gcc -c rand.c \ > ar rvs librand.a rand.o \ > del rand.o \ > move librand.a \djgpp\lib \ > copy rand.h \djgpp\include No, this is not correct. > By analogy, maybe in mingw I would do: > move librand.a c:\mingw\lib \ > copy rand.h c:mingw\include > > I am not at all sure about: > ar rvs librand.a rand.o \ The backslashes at the ends of the lines are wrong. > >From what I read, one possibility is to stick the libraries in > c:\mingw\local > or maybe c:\mingw\local\lib ? > This seems nice, because it keeps my libraries separate from mingw's. > Would mingw be smart enough to know to look there? Otherwise I guess I > would need to set LIBRARY_PATH? How? You can add -L c:/mingw/local/lib to your gcc link command line, *before* the -lrand, (and before any other -l references into that directory; one instance of -L suffices for any number of *following* -l references). Alternatively, you may adapt the gcc specs file to add that -L reference automatically, for all gcc invoked linking. This is explained in more detail, in the LibraryPathHOWTO. > How about the header files? Where do they go? > c:\mingw\local No; not a good idea. > c:\mingw\local\include ? That's a viable choice, but... > Would mingw be smart enough to know to look there? No; you have to tell it, as explained in the IncludePathHOWTO. > Maybe there's an INCLUDE_PATH? Yes, again as explained in the HOWTO; follow the link to CPATH and related environment variables. > Fiddling with Specs seems an option too, but it is too sketchy for me > to figure out. Well, the SpecsFileHOWTO explains it in comprehensive detail; in particular, the comment I added as a footnote covers precisely this customisation. -- Regards, Keith. |