marcov64 / Lsd

Lsd repository on GitHUB
35 stars 22 forks source link

extern char msg[]; before MODELBEGIN prevent compilation in the last 8-0 beta #51

Closed fl0rianB closed 3 years ago

fl0rianB commented 3 years ago

Hi,

My lsd file starts with: `//#define NO_POINTER_INIT

include "fun_head_fast.h"

extern char msg[]; MODELBEGIN`

We used it to be able to get quick information in the log window with: sprintf(msg, "\n something(%g)", v[20]); plog(msg); for example.

With the last version of 8.0 beta, compilation fails producing this kind of error: /usr/bin/ld: fun_tr6GD.o: warning: relocation againstmsg' in read-only section .text' /usr/bin/ld: fun_tr6GD.o: in functioninit_map()::{lambda(object, variable)#204}::operator()(object, variable) const': /home/flo/Apps/LSD/Work/PostTransit3/fun_tr6GD.cpp:4089: undefined reference to msg' /usr/bin/ld: /home/flo/Apps/LSD/Work/PostTransit3/fun_tr6GD.cpp:4089: undefined reference tomsg' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status make: *** [makefile:48: LSD] Error 1`

Is there any solution allow the compilation without removing all msg in the code? Thanks a lot, Florian

MCP1 commented 3 years ago

Hi Florian. Sorry for the message, but is the expected behavior for version 8. But the fix is very simple. You are trying to use an internal LSD buffer ("extern char msg[];") in your code. This was known to create some weird and hard to catch bugs, particularly when you use parallel computation of variables, So, in version 8, all public (global) buffers were finally removed, to prevent problems inside and outside of LSD, as they are not a good idea to start with. So, if you need a buffer like the now defunct "msg", simply replace the line "extern char msg[];" with "char msg[ 5000 ];", maybe replacing 5000 with the buffer size you need. Another alternative is to use legacy mode, replacing '#include "fun_head_fast.h"' with '#include "fun_head.h"', which will create a "msg" buffer for you but at the cost of slower execution of larger models.