tcc, g++ and va_args

30 Views Asked by At

I want to mix code compiled by tcc and g++, but if va_arg is called there is a link error. How to link it? Automation want more details, but I have nothing to add more here. Code is self-explanatory.

Sample codes:

/* args.c */
#include <stdarg.h>
#include "aaa.h"

void
args_va(int id, va_list ap)
{
        int c = va_arg(ap, int);
}

void
args(int id, ...)
{
        va_list ap;

        va_start(ap, id);
        args_va(id, ap);
        va_end(ap);
}

int
main(int argc, char **argv)
{
        args(1, 2, 3);
        aaa();
        return 0;
}

/* aaa.h */
#ifdef __cplusplus
extern "C" {
#endif

void aaa(void);

#ifdef __cplusplus
}
#endif


/* aaa.cpp */
#include "aaa.h"

void
aaa(void)
{
}

# Makefile
args.exe: args.o aaa.o
        g++ -o $@ args.o aaa.o -ltcc

args.o: args.c
        tcc -c args.c

aaa.o: aaa.cpp
        g++ -c aaa.cpp

After make:

g++ -o args.exe args.o aaa.o -ltcc
/usr/bin/ld: warning: args.o: missing .note.GNU-stack section implies executable stack
/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/bin/ld: args.o: in function `args_va':
args.c:(.text+0x39): undefined reference to `__va_arg'
collect2: error: ld returned 1 exit status

g++ (Debian 12.2.0-14) 12.2.0

tcc version 0.9.28rc 2023-11-08 mob@be8f8947 (x86_64 Linux)

0

There are 0 best solutions below