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 8407517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:23:13+00:00 2026-06-09T23:23:13+00:00

I have a static C library that I can build with different compile time

  • 0

I have a static C library that I can build with different compile time options (e.g. _BUILD_SMALL, _BUILD_FAST). It has a function

void Foo(void);

I would like to use a single instance of a benchmarking tool to benchmark the “small” and the “fast” versions of the library. I don’t want to use .dlls.

How can I link to the “small” and the “fast” libraries and alias the function names so I can call the small version and the fast version. Ideally it would look something like:

void benchmark(void)
{
  FAST_Foo();

  SMALL_Foo();
}

More information:

The library can be built with different optimizations options -Os versus -O3. Also, the algorithms vary slightly (i.e. cached values vs looking up values always). I want to compare the size vs speed tradeoffs of the different versions. I’d like the unit tests and benchmarking to be ran on both versions of the library the easiest way possible.

  • 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-09T23:23:15+00:00Added an answer on June 9, 2026 at 11:23 pm

    This is just a variation of the method as given by @Michał Górny (I run out of comment space there)…

    You could create an include file of the following form:

    /* Automatically created file - do not edit or ugly dinosaur will eat you */
    #ifndef PREFIX
    #  define RENAME(f)
    #else
    #  define RENAME(f) PREFIX ## f
    #endif
    
    /* list all the function and variables you want to rename here in one place */
    #define func_foo RENAME(func_foo)
    #define func_bar RENAME(func_bar)
    /* ... many more ... */
    
    #undef RENAME
    

    At least gcc allows you to specify the inclusion of a header file from command line with option -include rename.h (assuming this file is called rename.h). Because you use gcc lookalike options (-O3 and Os), I am assuming you use gcc in the rest of this answer. Otherwise, if your C compiler is reasonable, you should be able to do it in some similar way.

    You can create easily two or even three versions of your library that can be linked in at the same time if you want, by providing different options for your C compiler (here through CFLAGS setting):

    CFLAGS += -include rename.h -DPREFIX=fast_ -D_BUILD_FAST -O3 -DBENCHMARKING
    CFLAGS += -include rename.h -DPREFIX=small_ -D_BUILD_SMALL -Os -DBENCHMARKING
    CFLAGS += -D_BUILD_FAST -O2
    

    If your library header files look very regular and if you declare the library private functions static, then it is easy to extract the functions from those header files by some dummy script using very simple regular expressions to automatically generate the rename.h file for you. This is a natural build target if you are using make or something similar. All the global variables also need to be renamed using the same method to allow simultaneous use.

    There are three main points with this solution:

    1. The ugly renaming business can be hidden in one file, you do not need to edit the actual source files – especially you do not need to clutter the source files but can keep them clean and easy to read.
    2. The renaming can be easily automated, if you follow some simple principles (coding conventions followed for the header files and the header files will declare all the global variables and functions).
    3. There is no reason to make benchmarking more cumbersome by needing to run your test program multiple times (this is relevant if you are as lazy as I am and dislike repetive tasks as violently as I do – I know many people do not care, it is somewhat a matter of preference).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Objective-C/Cocoa project that incorporates a static library. That static library has
I want to build a static library that requires openssl for iPhone. It can't
I have a static library with two different targets: one to build for the
I have a static library (let's call it S) that uses a category (NSData+Base64
I was given an static library (.a extension file) that I have to use
I have a Visual Studio 2008 C++ project that outputs a static library and
I have a static library project that I inherited from another developer. I added
I build a static library that uses Objective-C++. When it is used in a
I have an Objective C static library that I am trying to import into
I have an monotouch application that includes an objective-c static library. The application runs

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.