Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Revamp, rip off wrong, insert minimal example
Source Link
drahnr
  • 6.9k
  • 5
  • 52
  • 76

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution toEdit: your question would besetup is correct. I got a working minmal example:

globals.h:

extern double g_pi;g_tst; 

globals.ccpp

g_pi#include "globals.h" double g_tst = 34.;0; 

For all other .c and main.h files:cpp

extern#include double"globals.h" #include g_pi;<stdio.h> #include <stdlib.h> int main() { fprintf (stderr, "g_tst = %lf \n", g_tst); return 0; } 

Also seeThe problem is within your buildsystem

See wikipedia

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution to your question would be:

globals.h:

double g_pi; 

globals.c

g_pi = 3.; 

For all other .c and .h files:

extern double g_pi; 

Also see wikipedia

You could simply use M_PI from the <math.h> include (there are other constants too).

Edit: your setup is correct. I got a working minmal example:

globals.h

extern double g_tst; 

globals.cpp

#include "globals.h" double g_tst = 4.0; 

main.cpp

#include "globals.h" #include <stdio.h> #include <stdlib.h> int main() { fprintf (stderr, "g_tst = %lf \n", g_tst); return 0; } 

The problem is within your buildsystem

See wikipedia

added 23 characters in body; added 6 characters in body
Source Link
drahnr
  • 6.9k
  • 5
  • 52
  • 76

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution to your question would be: globals

globals.h:

double g_pi; 

globals.c

g_pi = 3.; 

For all other .c and .h files:

extern double g_pi; 

Also see wikipedia

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution to your question would be: globals.h:

double g_pi = 3.; 

For all other .c files:

extern double g_pi; 

Also see wikipedia

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution to your question would be:

globals.h:

double g_pi; 

globals.c

g_pi = 3.; 

For all other .c and .h files:

extern double g_pi; 

Also see wikipedia

Source Link
drahnr
  • 6.9k
  • 5
  • 52
  • 76

You could simply use M_PI from the <math.h> include (there are other constants too).

A direct solution to your question would be: globals.h:

double g_pi = 3.; 

For all other .c files:

extern double g_pi; 

Also see wikipedia