Menu

#195 Linking libraries breaks arguments

None
closed-rejected
library (1)
5
2024-01-31
2024-01-31
Nikita Koss
No

Some functions stop compiling if you link libraries. For example, the assert function. Without linking the library compiles normally.

[build] [8/15  13% :: 0.102] C:\PROGRA~1\SDCC\bin\sdcc.exe -DDGUS_BULTIN_DELAY=1 -DDGUS_PRINTF=1 -DDGUS_PRINTF_UART=2 -ID:\Nevoton\DGUSlib\include -DSDCC_CYGNAL --no-peep --int-long-reent --float-reent --debug --nolabelopt --model-large --std-sdcc2x -o examples\assert\CMakeFiles\assert.dir\assert.c.rel -c D:\Nevoton\DGUSlib\examples\assert\assert.c
[build] FAILED: examples/assert/assert.ihx 
[build] C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\SDCC\bin\sdcc.exe -DSDCC_CYGNAL --no-peep --int-long-reent --float-reent --debug --nolabelopt examples\assert\CMakeFiles\assert.dir\assert.c.rel -o examples\assert\assert.ihx --xram-loc 0x8000 --xram-size 0x8000 --stack-auto --model-large --std-sdcc2x  dgus.lib && C:\Windows\system32\cmd.exe /C "cd /D D:\Nevoton\DGUSlib\build\examples\assert && "C:\Program Files\SDCC\bin\makebin.exe" -p D:/Nevoton/DGUSlib/build/examples/assert/assert.ihx T5L51.bin""
[build] 
[build] ?ASlink-Warning-Undefined Global '___assert_PARM_2' referenced by module 'assert'
[build] 
[build] ?ASlink-Warning-Undefined Global '___assert_PARM_3' referenced by module 'assert'
[build] 
[build] ?ASlink-Warning-Undefined Global '___assert_PARM_4' referenced by module 'assert'

assert.c

#include <assert.h>
#include <stdio.h>

#include "dgus.h"

void uart2_init(uint32_t baud_rate);

volatile int i = 42;
int a[]        = {1, 0};

void main(void) {
  sys_init();
  uart2_init(115200);
  i = 0;
  assert(i);
  assert(i - 42);
#ifdef __SDCC       // SDCC assert is always C23-compliant
  assert(a[1, 0]);  // C23 requires C23 to be implemented as variadic macro,
                    // which is meant for the use of compound literals in the
                    // argument. But the easiest way to test that is by using a
                    // comma operator not surrounded by ().
#endif
  while (1) {}
}

MAP-file in attach

1 Attachments

Discussion

  • Nikita Koss

    Nikita Koss - 2024-01-31

    Oh, I'm sorry. The library itself has no effect. Only the --stack-auto flag has an effect.

     
  • Maarten Brock

    Maarten Brock - 2024-01-31
    • status: open --> closed-rejected
    • assigned_to: Maarten Brock
    • Group: -->
     
  • Maarten Brock

    Maarten Brock - 2024-01-31

    Some options need to be used the same for compiling and for linking. The memory model and --stack-auto are the most notable ones.

    And unless you compile your own libraries I recommend not to use --float-reent and --int-long-reent.

     
    👍
    1

Log in to post a comment.