Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't build on linux #76

Closed
mulle-nat opened this issue Jun 6, 2022 · 3 comments · Fixed by #77
Closed

Doesn't build on linux #76

mulle-nat opened this issue Jun 6, 2022 · 3 comments · Fixed by #77

Comments

@mulle-nat
Copy link
Contributor

mulle-nat commented Jun 6, 2022

You get a lot of linker errors like

/usr/bin/ld: obj/cengine.o:/home/src/src/unix/Corange/./include/cengine.h:80: multiple definition of `debug_str'; obj/casset.o:/home/src/src/unix/Corange/./include/cengine.h:80: first defined here
/usr/bin/ld: obj/cengine.o:/home/src/src/unix/Corange/./include/cengine.h:79: multiple definition of `debug_buf'; obj/casset.o:/home/src/src/unix/Corange/./include/cengine.h:79: first defined here

The problem is that the cengine.h header defines global buffer variables, that are compiled into each file:

#define ERROR_BUFFER_SIZE   2048*4
#define DEBUG_BUFFER_SIZE   2048*4
#define WARNING_BUFFER_SIZE 2048*4

...

char error_buf[ERROR_BUFFER_SIZE];
char error_str[ERROR_BUFFER_SIZE];

char warning_buf[WARNING_BUFFER_SIZE];
char warning_str[WARNING_BUFFER_SIZE];

char debug_buf[DEBUG_BUFFER_SIZE];
char debug_str[DEBUG_BUFFER_SIZE];

There are two quick solutions

  • turn them into declarations with extern in cengine.h and define them in cengine.c once
  • make these buffers local variables to the block, like so:
#define error(MSG, ...) { \  
  char error_buf[ERROR_BUFFER_SIZE]; \
  char error_str[ERROR_BUFFER_SIZE]; \
  snprintf(error_str,(ERROR_BUFFER_SIZE-1), "[ERROR] (%s:%s:%i) ", __FILE__, __func__, __LINE__); \
  snprintf(error_buf,(ERROR_BUFFER_SIZE-1), MSG, ##__VA_ARGS__); strcat(error_str, error_buf);    \
  error_(error_str); }

This is thread-safer as a bonus, but putting 16K on the stack seems somewhat excessive.

@blogdron
Copy link
Contributor

blogdron commented Jun 6, 2022

This error is caused by a change in the default behavior of the compiler. If you have an idea how to make it beautiful, we are waiting for the patch =)

@mulle-nat
Copy link
Contributor Author

I outlined two solutions. I am not sure though, which one is preferable.

@orangeduck
Copy link
Owner

I think marking these as extern makes the most sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants