🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.misc
Article #2061

Understanding gcc/unix

#2061
From: Jan Danielsson
Date: Fri, 24 Mar 2006 14:11
86 lines
3599 bytes
Hello all,

   First of all, my background consists mainly of OS/2. Now I'm trying
to start working in unix:ish environments. Primarily NetBSD.

   I'm having some trouble understanding how to do basic things like
compiling and linking. I have written several programs which use
standard libraries, but as soon as I try to use custom libraries, I run
into problems.

   In a particular case, I'm trying to use apache's apr library. I have
written a small test:

----------------------------------
#include <stdlib.h>

#include <apr-0/apr.h>
#include <apr-0/apr_pools.h>
#include <apr-0/apr_thread_proc.h>

void *thread(apr_thread_t *thrd, void *param)
{
  apr_sleep(500);
  puts("Yo!");
  apr_sleep(500);
  puts("Yo!");
  apr_sleep(500);

  apr_thread_exit(thrd, 0);
}

int main(void)
{
  apr_status_t rc = 0;
  apr_thread_t *new_thread = NULL;
  apr_pool_t *pool = NULL;

  apr_initialize();
  atexit(apr_terminate);
  apr_pool_create(&pool, NULL);

  rc = apr_thread_create(&new_thread, NULL, thread, NULL, pool);

  apr_sleep(3000);

  return EXIT_SUCCESS;
}
----------------------------------

   I compile (and link) with this:

$ gcc -L/usr/pkg/lib -lapr-0 -I/usr/pkg/include aprtest.c

   This produces an a.out file. But when I try to run ./a.out, I get this:

$ ./a.out
Shared object "libapr-0.so.0" not found

   However:

$ locate libapr-0.so.0
/usr/pkg/lib/libapr-0.so.0
/usr/pkg/lib/libapr-0.so.0.9.7

   In OS/2, I would simply fix my LIBPATH. But I have no idea what I
need to do in NetBSD to make it work. Any tips?


   Also, I would like to know how to make my program as portable as
possible in unix:ish environments (with regards to the build system -- I
already know how to write portable code). I mean, if I write a makefile
which refers to /usr/pkg/lib/libapr-0.so, that won't be very portable. I
assume this is what the normally-required "./configure" is for. So what
is "./configure"? Is it a script that I need to write myself which
checks what system it is running under, and create the appropriate
makefile? This seems quite volatile, since even if I determine that the
program is being built under NetBSD, there's no guarantee that packages
are installed under /usr/pkg. Or does the script need to check that too?
That would require quite a big script for all the possible combinations
of systems out there.. So I get the feeling that there's a much cleaner
way to do this.

-- 
Kind Regards,
Jan Danielsson
Te audire non possum. Musa sapientum fixa est in aure.
Technical Details
Message-ID: <4423fd5b$1@griseus.its.uu.se>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!news.banetele.no!uio.no!newsfeed1.funet.fi!newsfeeds.funet.fi!newsfeed.sunet.se!news01.sunet.se!130.238.4.166.MISMATCH!griseus.its.uu.se!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f72b0,2e62ec248b0c5e44,start
X-Google-Thread: f65d0,2e62ec248b0c5e44,start
X-Google-Attributes: gidf72b0,gidf65d0,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 24 Mar 2006 15:11:42 +0100
From: Jan Danielsson <jan.danielsson@gmail.com>
Organization: La Cosa Nostra
User-Agent: Thunderbird 1.5 (Windows/20051201)
MIME-Version: 1.0
Newsgroups: comp.unix.misc,gnu.gcc
Subject: Understanding gcc/unix
X-Enigmail-Version: 0.94.0.0
OpenPGP: id=9E389A82;
 url=http://user.it.uu.se/~jada3673/jan_danielsson.asc
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: nl102-238-206.student.uu.se
Message-ID: <4423fd5b$1@griseus.its.uu.se>
X-Trace: griseus.its.uu.se 1143209307 130.243.238.206 (24 Mar 2006 15:08:27 +0200)
Lines: 86
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!news.banetele.no!uio.no!newsfeed1.funet.fi!newsfeeds.funet.fi!newsfeed.sunet.se!news01.sunet.se!130.238.4.166.MISMATCH!griseus.its.uu.se!not-for-mail