|
From: Nathan S. <nat...@pk...> - 2009-03-14 09:25:19
|
Hey all, I'm working on a project involving DirectShow and GTK+. I recently setup a fresh MSYS and MinGW environment on a laptop I am using to build the project with. The issue is that whenever I try to compile and link the simplest code (like the gtkmm hello world example) as follows: g++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp all I get are a bunch of linker errors, as though it's not even trying to link. pkg-config outputs the proper goods, and the paths are correct, so I know that's working right. However, when I issue the same command (copying and pasting the goods from pkg-config of course) in a command prompt (CMD.exe), it compiles and links no problem. I cannot figure out why this is. Having to switch back and forth between shells is a pain, and using pkg-config is a real time saver. Does anyone know why this may be happening? -Nathan |
|
From: Nathan S. <nat...@pk...> - 2009-03-14 10:02:58
|
Nathan Schulte wrote: > Hey all, I'm working on a project involving DirectShow and GTK+. I > recently setup a fresh MSYS and MinGW environment on a laptop I am using > to build the project with. > > The issue is that whenever I try to compile and link the simplest code > (like the gtkmm hello world example) as follows: > > g++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp > > all I get are a bunch of linker errors, as though it's not even trying > to link. pkg-config outputs the proper goods, and the paths are > correct, so I know that's working right. > > However, when I issue the same command (copying and pasting the goods > from pkg-config of course) in a command prompt (CMD.exe), it compiles > and links no problem. I cannot figure out why this is. Having to > switch back and forth between shells is a pain, and using pkg-config is > a real time saver. > > Does anyone know why this may be happening? > > -Nathan > > > ------------------------------------------------------------------------------ > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com I have found the issue. It seems as though any -l options need to come _after_ the source files. g++ main.cpp `pkg-config --libs --cflags gtkmm-2.4` is ok, but gt++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp is not. The command I was piecing together in the dos prompt had main.cpp before the pkg-config output, causing the effect I described, but not because of why I described. Is this a bug, or is this how gcc/g++ work? |
|
From: Keith M. <kei...@us...> - 2009-03-14 22:53:01
|
On Saturday 14 March 2009 10:02:21 Nathan Schulte wrote: > I have found the issue. It seems as though any -l options need to > come _after_ the source files. > > g++ main.cpp `pkg-config --libs --cflags gtkmm-2.4` > > is ok, but Except that now, the CFLAGS may be misplaced. The definitively correct usage is as Tor has described. > gt++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp > > is not. > > [...] > > Is this a bug, No. > or is this how gcc/g++ work? It is how compilers, and in particular linkers, in general, work on unixy platforms. (GCC is part of a unixy tool suite). -- Regards, Keith. |
|
From: Nathan S. <nat...@pk...> - 2009-03-14 23:32:44
|
Keith Marshall wrote: > It is how compilers, and in particular linkers, in general, work on > unixy platforms. (GCC is part of a unixy tool suite). I'm very familiar with the autotools/gcc build environment on UNIX(linux mostly), however, I have never noticed this before. This could be attributed to the fact that when I was writing Makefiles by hand for simple projects, I never really had to link to any libraries (other than the standard library, but gcc takes care of that internally), and then I immediately learned how to used the GNU Autotools (autoconf/automake and friends) which forces proper ordering (doesn't force per say, but if you're going to script those pieces by hand, why used automake?) To all who have replied, thanks for the clarification and thoughts. I'm glad I asked. -Nathan |
|
From: Tor L. <tm...@ik...> - 2009-03-14 10:09:09
|
> g++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp Try this instead: g++ `pkg-config --cflags gtkmm-2.4` main.cpp `pkg-config --libs gtkmm-2.4` > pkg-config outputs the proper goods, Not really. In general one should put libraries after object (or, in your simple case, source) files on the command line. That is how it has traditionally been since the dawn of time. It's just on Linux (and other platforms that use ELF?) that one can put libraries before the object files. So unfortunately this "pkg-config --cflags --libs" meme is very widespread. --tml |
|
From: Keith M. <kei...@us...> - 2009-03-14 22:45:52
|
On Saturday 14 March 2009 10:08:52 Tor Lillqvist wrote: > > g++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp > > Try this instead: > > g++ `pkg-config --cflags gtkmm-2.4` main.cpp `pkg-config --libs > gtkmm-2.4` > > > pkg-config outputs the proper goods, > > Not really. In general one should put libraries after object (or, > in your simple case, source) files on the command line. That is how > it has traditionally been since the dawn of time. It's just on > Linux (and other platforms that use ELF?) that one can put > libraries before the object files. So unfortunately this > "pkg-config --cflags --libs" meme is very widespread. Unfortunate indeed. Even on Linux, this common misuse is incorrect; it is only when the libraries in question are *shared*, that the ELF linker will forgive the incorrect ordering; such misuse, in the case of *static* libraries, will be punished equally on all platforms. -- Regards, Keith. |
|
From: Keith M. <kei...@us...> - 2009-03-14 10:15:17
|
On Saturday 14 March 2009 09:18:25 Nathan Schulte wrote: > The issue is that whenever I try to compile and link the simplest > code (like the gtkmm hello world example) as follows: > > g++ `pkg-config --libs --cflags gtkmm-2.4` main.cpp > > all I get are a bunch of linker errors, [...] > > Does anyone know why this may be happening? Looks like an argument ordering issue: no external references in main.cpp can *ever* be resolved, because there are no libraries specified *after* it, to provide resolution. Conversely, any libraries specified by your pkg-config command will be simply and silently discarded, because there are no dependencies known for them, *before* they are parsed; (those will be defined in main.cpp, which is parsed too late). -- Regards, Keith. |