Thread: library taking values from from header file

  1. #1
    Registered User
    Join Date
    Sep 2023
    Posts
    1

    library taking values from from header file

    I am working on a library that is used in a piece of firmware by a customer, but is precompiled so it is not exposed to the customer. The customer needs to provide some settings for the firmware in a header file that is used by the library. When I compile the library and run the firmware, the library sometimes uses values from the header file that was used in the compilation of the library, rather than the header file of the same name that is in the firmware folder. This is not conistent, some values are taken from the right header file (#defines usually), while a set of arrays that contain measurement values from the customer come from the wrong header file.
    For example, I have in the header file that is used for the firmware:
    Code:
    static const float scaling[5][5] = {     {0.2, 0.2, 0.2, 0.2, 0.2 },
        {0.2, 0.2, 0.2, 0.2, 0.2 },
        {0.2, 0.2, 0.2, 0.2, 0.2 },
        {0.2, 0.2, 0.2, 0.2, 0.2 },
        {0.2, 0.2, 0.2, 0.2, 0.2 },
       
    };
    and in the header file used to compile the library:
    Code:
    static const float scaling[5][5] = {     {1, 1, 1, 1, 1 },
        {1, 1, 1, 1, 1 },
        {1, 1, 1, 1, 1 },
        {1, 1, 1, 1, 1 },
        {1, 1, 1, 1, 1 },
       
    };
    and in the c file of the library:
    Code:
    float scale_output=scaling[2][2];
    this gives a scale_output value of 1, instead of 0.2.

    What is causing this issue and how do I get around it while still allowing the customer to change these values without exposing the library?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    How are you building the library? Using a makefile?

    How do you tell your build to use the customer header file rather than the library header file?

    Typical things to watch out for are paths (especially relative paths), and the relative ages of files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    I'm wondering if he's hoping to replace the array data in the pre-compiled library with data from the header file included in the library-using program. That won't work. You could make the library's array extern and define the actual array in the user code. (In this case there's no "default" and the array must be in the user code, even if it is the default.)
    Library header file:
    Code:
    extern const float scaling[5][5]; // externally defined object
    User-code header file:
    Code:
    const float scaling[5][5] = {
        { 0.2, 0.2, ... },
        { 0.2, 0.2, ... },
        ...
    };
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Library file and header file in GCC?
    By mhrsolanki2020 in forum C Programming
    Replies: 16
    Last Post: 12-22-2012, 11:51 PM
  2. GCC Header File Library Flag Listing?
    By LinuxSmith in forum Linux Programming
    Replies: 9
    Last Post: 08-15-2010, 07:42 PM
  3. Need Help With Header library file..
    By kensam in forum C Programming
    Replies: 8
    Last Post: 01-27-2010, 01:39 PM
  4. Gnu C++ Library Header file question?
    By xddxogm3 in forum C++ Programming
    Replies: 13
    Last Post: 10-01-2003, 03:48 PM
  5. C++ >> Standard Library >> Header File
    By hrk2006 in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2003, 08:30 PM

Tags for this Thread