Re: How to write code in FreeBSD
On Saturday 02 March 2002 09:41 am, Brian T. Schellenberger wrote: > On Saturday 02 March 2002 06:57 am, Aleksander Rozman - Andy wrote: > > Hi ! > > > > I was wondering if there are any guidelines how to write code in FreeBSD. > > I have taken a look at several code of FreeBSD but each is written > > differently? Problem is I don't know which is preferred way. > > > > Reason I am asking this is that I am trying to add some code to kernel. > > Compile is OK, no error, no warning, but on link all variables defined > > with extern are marked as : undefined reference to 'variable', variable > > is extern and .h file which has it defined is included... Where can be > > the problem?? Another problem is that I get multiple definition > > error...how can I get over this. I got Andy to send his original code, and I believe that I've diagnosed the root of the problem: The code was assuming that KERNEL was defined when building the kernel (I gather that KERNEL is defined when building a Linux kernel), but under FreeBSD, it seems, KERNEL is *not* defined, but _KERNEL is defined instead. (Though I'm not sure whether it's defined under the same circumstances.) Even so I'm not sure that his code is perfectly correct ANSI C, technically speaking, since it then appears that it would wind up with multiple copies of the variables defined, but I'm pretty darn sure that gcc & ld tolerate this just fine--the proximate cause of the difficulty lay in expecting KERNEL to be defined and having an #ifdef KERNEL check in the 'h' file that caused the definitions to never to be read. -- Brian T. Schellenberger . . . . . . . [EMAIL PROTECTED] (work) Brian, the man from Babble-On . . . . [EMAIL PROTECTED] (personal) ME --> http://www.babbleon.org http://www.eff.org <-- GOOD GUYS --> http://www.programming-freedom.org To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: How to write code in FreeBSD
On Sat, Mar 02, 2002 at 12:57:29PM +0100, Aleksander Rozman - Andy wrote: > I was wondering if there are any guidelines how to write code in FreeBSD. I > have taken a look at several code of FreeBSD but each is written > differently? Problem is I don't know which is preferred way. Most code in FreeBSD is written according to the rules in the style(9) man page. Code which has been imported from other projects is usually not subject to these guidelines. > Reason I am asking this is that I am trying to add some code to kernel. > Compile is OK, no error, no warning, but on link all variables defined with > extern are marked as : undefined reference to 'variable', variable is > extern and .h file which has it defined is included... Where can be the > problem?? Another problem is that I get multiple definition error...how can > I get over this. It's almost impossible to say without seeing the code. Can you produce a short example and say how you are compiling and linking it into the kernel. David. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: How to write code in FreeBSD
On Saturday 02 March 2002 06:57 am, Aleksander Rozman - Andy wrote: > Hi ! > > I was wondering if there are any guidelines how to write code in FreeBSD. I > have taken a look at several code of FreeBSD but each is written > differently? Problem is I don't know which is preferred way. > > Reason I am asking this is that I am trying to add some code to kernel. > Compile is OK, no error, no warning, but on link all variables defined with > extern are marked as : undefined reference to 'variable', variable is > extern and .h file which has it defined is included... Where can be the > problem?? Another problem is that I get multiple definition error...how can > I get over this. There's notthing "special" about FreeBSD in this regard. You have to have *some* file which does *not* refer to the variables as "extern" since "extern" means "defined someplace else in the link," and if *every* file says tha they are defined in some *other* file, well, then, they never get defined--just declared. THis is a basic "C" quesiton, not a "FreeBSD" question. -- Brian T. Schellenberger . . . . . . . [EMAIL PROTECTED] (work) Brian, the man from Babble-On . . . . [EMAIL PROTECTED] (personal) ME --> http://www.babbleon.org http://www.eff.org <-- GOOD GUYS --> http://www.programming-freedom.org To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: How to write code in FreeBSD
On Sat, 02 Mar 2002 12:57:29 +0100 Aleksander Rozman - Andy <[EMAIL PROTECTED]> wrote: > > Hi ! > > I was wondering if there are any guidelines how to write code in FreeBSD. I > have taken a look at several code of FreeBSD but each is written > differently? Problem is I don't know which is preferred way. look at style(9) -- /"\ http://corecode.ath.cx/ \ / \ ASCII Ribbon Campaign / \ Against HTML Mail and News msg32308/pgp0.pgp Description: PGP signature
How to write code in FreeBSD
Hi ! I was wondering if there are any guidelines how to write code in FreeBSD. I have taken a look at several code of FreeBSD but each is written differently? Problem is I don't know which is preferred way. Reason I am asking this is that I am trying to add some code to kernel. Compile is OK, no error, no warning, but on link all variables defined with extern are marked as : undefined reference to 'variable', variable is extern and .h file which has it defined is included... Where can be the problem?? Another problem is that I get multiple definition error...how can I get over this. Please help Andy ** * Aleksander Rozman - Andy * Fandoms: E2:EA, SAABer, Trekkie, Earthie * * [EMAIL PROTECTED] * Sentinel, BH 90210, True's Trooper, * *[EMAIL PROTECTED] * Heller's Angel, Questie, Legacy, PO5, * * Maribor, Slovenia (Europe) * Profiler, Buffy (Slayerete), Pretender* * ICQ-UIC: 4911125 * * PGP key available *http://www.atechnet.dhs.org/~andy/ * ** To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message