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

Issues when trying to compile/build with cosmopolitan libc #297

Open
mingodad opened this issue Sep 29, 2022 · 0 comments
Open

Issues when trying to compile/build with cosmopolitan libc #297

mingodad opened this issue Sep 29, 2022 · 0 comments

Comments

@mingodad
Copy link

I understand that this use case is not the one intended by this project but it seems to reveal some edge cases when trying to compile/build with cosmopolitan libc (https://github.com/jart/cosmopolitan).

I manged to compile/build c2m using cosmopolitan libc with this shell script:

# run gcc compiler in freestanding mode
base_dir="mir-source-path"
do_compile() {
	gcc -g -Os -static -fno-pie -no-pie -nostdlib -nostdinc -pipe \
	  -fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
	  -include cosmopolitan.h \
	  -DWHITHOUT_STD_HEADERS -I$base_dir \
	  -Wno-abi -fsigned-char -fno-tree-sra -fno-ipa-cp-clone -DxMIR_PARALLEL_GEN \
	  -c -o $2 $1
}
do_link() {
	gcc -g -Os -static -fno-pie -no-pie -nostdlib -nostdinc -pipe \
	  -fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
	  -DBASECC='"$(GCC)"' \
	  -o $1.com.dbg $2 -Wl,--gc-sections -fuse-ld=bfd -Wl,--gc-sections \
	  -Wl,-T,ape.lds crt.o ape-no-modify-self.o cosmopolitan.a
	objcopy -S -O binary $1.com.dbg $1.com
}

do_compile $base_dir/mir.c mir.o
do_compile $base_dir/mir-gen.c mir-gen.o
do_compile $base_dir/c2mir/c2mir.c c2mir.o
do_compile $base_dir/c2mir/c2mir-driver.c c2mir-driver.o

do_link c2m "mir.o mir-gen.o c2mir.o c2mir-driver.o"

And adding a conditional macro wrapper around standard headers like this:

/* This file is a part of MIR project.
   Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/

#ifndef MIR_H

#define MIR_H

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_WIN32) && !defined(_WIN64)
#error "MIR does not work on 32-bit Windows"
#endif

#ifndef WHITHOUT_STD_HEADERS ///wrapper to conditionally exclude
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#endif ///wrapper end
#include "mir-dlist.h"
#include "mir-varr.h"
#include "mir-htab.h"

Then when I try to compile one example using cosmopolitan.h (even with the default c2m) I'm getting several warning/errors like:

./ape.elf ./c2m.com exprtk_functional_test-small.c
...
./cosmopolitan.h:363:25: syntax error on identifier (expected ';'):
./cosmopolitan.h:363:25: syntax error on identifier (expected '<declarator>'):
./cosmopolitan.h:375:23: syntax error on identifier (expected ';'):
./cosmopolitan.h:375:23: syntax error on identifier (expected '<declarator>'):
./cosmopolitan.h:395:9: syntax error on struct (expected '<declarator>'):
./cosmopolitan.h:1728:18: syntax error on const (expected 'identifier'):
./cosmopolitan.h:1728:18: syntax error on const (expected '<declarator>'):
./cosmopolitan.h:1944:16: syntax error on ( (expected '<declarator>'):
./cosmopolitan.h:1945:16: syntax error on ( (expected '<declarator>'):
./cosmopolitan.h:1947:12: syntax error on void (expected 'identifier'):
...

Test file:

#include "cosmopolitan.h"
int main(int argc, char *argv[]) { 
  printf("hello world\n");
  return 0;
}
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

No branches or pull requests

1 participant