Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:48:48+00:00 2026-06-01T02:48:48+00:00

Its a long time since I’ve used C but now I’m trying to compile

  • 0

Its a long time since I’ve used C but now I’m trying to compile a short script that gets server-stats from the Apache-Portable-Runtime (APR).

Header files located at /usr/include/apr-1/apr*.h and libs are located at /usr/lib64/libapr-1.*

Source files can be found on the official APR site http://apr.apache.org/docs/apr/1.3/files.html.

/* test.c */
#include <stdio.h>
#include <stdlib.h>
#include <apr_general.h>
#include <apr_time.h>

int main(int argc, const char *argv[])
{
    apr_time_t t;
    t = apr_time_now();
    printf("The current time: %" APR_TIME_T_FMT "[us]\n", t);
    return 0;
}

When I try and compile I get the following error (which I believe is a linking issue):

~> gcc -Wall $(apr-1-config --cflags --cppflags --includes --link-ld) test.c -o test.bin
/tmp/cc4DYD2W.o: In function `main':
test.c:(.text+0x10): undefined reference to `apr_time_now'
collect2: ld returned 1 exit status

My environment is gentoo:

~> uname -a
Linux alister 2.6.32.21-grsec-gt-r2 #1 SMP Tue Sep 7 23:54:49 PDT 2010\
x86_64 Intel(R) Xeon(R) CPU L5640 @ 2.27GHz GenuineIntel GNU/Linux`
~> gcc -v 
gcc version 4.3.4 (Gentoo 4.3.4 p1.1, pie-10.1.5)
~> emerge --search "%@^dev-lib.*apr"
*  dev-libs/apr
   Latest version installed: 1.3.9
*  dev-libs/apr-util
   Latest version installed: 1.3.9

Does anyone with more experience with C on Linux have any suggestions for me to get this working?

As always thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:48:50+00:00Added an answer on June 1, 2026 at 2:48 am

    I finally got around to looking into this.

    gcc mentions -l twice in different contexts:

    Linker Options
    object-file-name -llibrary ...
    Directory Options
    ... -Idir -Ldir ...
    

    so I moved the -llib after the object name (to get the 2nd context) and it compiled!

    APR_CFG=$(apr-1-config --cflags --cppflags --includes --link-ld) 
    gcc -Wall test.c -o test.bin $APR_CFG
    ./test.bin
    The current time: 1332999950442660[us]
    

    I’m not fully sure I understand the linking order and why it didn’t work before (if someone could shed some light on that it would be fantastic) but for now I have enough to continue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Its been a long time since I have programmed in C++, but I know
I have used Eclipse for a very long time. It has its problems, but
Its been a long time since I had to do anything but minor fixes
Its been a long time since i used php and i need some help
It's been now a long time since I try to figure out how to
I am trying to run a cgi script, its a long script so i
So long story short, im trying to build a chat application....well its already built
Its been a long time since I've needed to crack open an .htaccess file...
Its been a while since I worked in asp.net and a very long time
It's been a long time since I've done C++ and I'm running into some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.