0

I have a C static library with algo_start.h and algo_start.c. In algo_start.c I have defined global variable like this:

static algo_start_t algo_start = {INTERNAL_STATE_IDLE, EXTERNAL_STATE_IDLE, NULL, 0, 0, 0, 0};

In newly created C project I included this static library, included algo_start.h, and tried to use functions defined in algo_start.h, but I get en error undefined reference to algo_start. I don't understand what and why (this) happens.

If I define algo_start variable in algo_start.h, the project compiles with no errors.

My environment is Windows 10, CodeBlocks IDE with mingw compiler.

user3007875
  • 123
  • 7
  • Because the library is not linked? – MikeCAT Jul 08 '21 at 11:08
  • Please post the complete code with your `main()` function – kiner_shah Jul 08 '21 at 11:09
  • You need to show how you use that library and what error you get. Defining a variable as static makes it invisible for any other source file. – Gerhardh Jul 08 '21 at 11:15
  • @Gerhardh I use that static variable only in algo_start.c, not anywhere else, because I want encapsulation. – user3007875 Jul 08 '21 at 12:59
  • I don't think this is possible. If you only use that variable in the same C file where you define it, you should either get the variable included or not get any reference to it. If the linked duplicate does not solve your problem you should as a new question where you include a [MCVE](https://stackoverflow.com/help/mcve). This means all files related to your affected variable stripped down to a minimum that still shows the problem. – Gerhardh Jul 08 '21 at 19:22

0 Answers0