[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

question about correct usage of gnulib

From: Lorenzo Bettini
Subject: question about correct usage of gnulib
Date: Sun, 24 Apr 2011 10:39:32 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8


I've been using gnulib for some years now in my GNU packages, but I was wondering whether I'm using correctly, since some people reported some compilation errors on some architectures...

I'm using getopt module, and on that architecture the user gets this compilation error

g++ -DHAVE_CONFIG_H -I. -I.. -I../src/skels -I../lib -I../lib -g -O2 -MT yyerror.o -MD -MP -MF .deps/yyerror.Tpo -c -o yyerror.o yyerror.cc
../lib/getopt.h:194: error: redefinition of ‘struct option’
/usr/include/getopt.h:54: error: previous definition of ‘struct option’

though that source file does not use getopt, but probably gets to use stdlib (which is required by getopt module if I'm not wrong)... it probably uses stdlib header file when including C++ string header file...

now, on the manual I read

"These Gnulib substitute header files rely on <config.h> being already included. Furthermore <config.h> must be the first include in every compilation unit. This means that to all your source files and likely also to all your tests source files you need to add an ‘#include <config.h>’ at the top. Which source files are affected? Exactly those whose compilation includes a ‘-I’ option that refers to the Gnulib library directory. "

and that's something I didn't do: I was including config.h only in those files that rely on getopt (or on another constants set in config.h).

So the compilation problem goes away if I put config.h in all source files, but is that really necessary?

Would it be correct to put config.h only say in file1.cpp (and use the
‘-I’ option that refers to the Gnulib library directory for that file only), and not in file2.cpp and file3.cpp (where I don't use -I to refer to gnulib library directory), and then link all the 3 files together by also putting -lgnu?

or should I do something else?

thanks in advance

Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]