c3c icon indicating copy to clipboard operation
c3c copied to clipboard

C headers created by c3c is not compatible for C compilers.

Open kcvinker opened this issue 1 year ago • 27 comments

When creating dlls with c3c, it is a nice feature to create C headers automatically. But this header file is not working in c compilers like MSVC. Please improve this feature so that we use this header files straight in MSVC. Now type names are showing with module name like abc.type.

kcvinker avatar Feb 06 '24 15:02 kcvinker

Can you check if this looks better with 0.5.4?

lerno avatar Feb 15 '24 20:02 lerno

@lerno , Sure.

Edit: What happened ? I couldn't find the download files for 0.5.4.

kcvinker avatar Feb 15 '24 21:02 kcvinker

@lerno, This is the error I see.

1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math_random.c3:3:11) Error: 'Random' would shadow a previous declaration.

1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math.random.c3:3:11) Note: The previous use of 'Random' was here.

kcvinker avatar Feb 16 '24 00:02 kcvinker

What did you do to get that error?

lerno avatar Feb 16 '24 08:02 lerno

@lerno, The one and only use for math library in my code is this.

import std::math;
macro clip(x) {
	return math::clamp(x, 0, 255);
}

kcvinker avatar Feb 16 '24 10:02 kcvinker

If you just compile a file, do you get the same error?

lerno avatar Feb 16 '24 10:02 lerno

Because somehow you've managed to insert the same symbol twice, and I just can't see how that could happen. But apparently it does, so I'm trying to find out how...

lerno avatar Feb 16 '24 11:02 lerno

If you just compile a file, do you get the same error?

Let me try that.

kcvinker avatar Feb 16 '24 11:02 kcvinker

@lerno I just tested with sample dll code. This time, I didn't used any math lib code. See this is my source code.

module dlltest;
fn void sample(int x) @export("MySampleFunc")
{
	int b = x + 2;
}

fn int testFunc(int y) @export("My_test_func")
{
	return y + 8;
}

And this is the start position of the error message.

 c3c build dlltest
1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math_random.c3:3:11) Error: 'Random' would shadow a previous declaration.

1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math.random.c3:3:11) Note: The previous use of 'Random' was here.

kcvinker avatar Feb 16 '24 12:02 kcvinker

Can you show me the project file?

lerno avatar Feb 16 '24 12:02 lerno

@lerno Here is my project.json

{
  // language version of C3
  "langrev": "1",
  // warnings used for all targets
  "warnings": [ "no-unused" ],
  // directories where C3 library files may be found
  "dependency-search-paths": [],
  // libraries to use for all targets
  "dependencies": [ ],
  
  "linker-search-paths": [],

  "linked-libraries": [],
  // authors, optionally with email
  "authors": [ "kcvinker" ],
  // Version using semantic versioning
  "version": "0.1.0",
  // sources compiled for all targets
  "sources": [ "./**"],
  // Targets
  "targets": {
    "dlltest": {
      // executable or library
      "type": "dynamic-lib"
      // additional libraries, sources
      // and overrides of global settings here
    },
  },
  
  // Debug information, may be 'none', 'full' and 'line-tables'
  "debug-info": "full",
  // Architecture and OS target:
  "target": "windows-x64",
  // The size of the symtab, which limits the amount
  // of symbols that can be used. Should usually not
  // be changed.
  //"symtab": 4194304,
  // "none", "pic", "PIC", "pie", "PIE"
  "reloc": "none",
  // Trap on signed and unsigned integer wrapping
  // for testing
  "trap-on-wrap": false,
  // Use / don't use soft float, value is otherwise target default
  "soft-float": false,
  // Vector settings on x86: none/native/mmx/sse/avx/avx512
  "x86vec": "sse",
  // CPU name, used for optimizations in the LLVM backend
  "cpu": "generic",
  // Output location, relative to project file
  "output": "./build",
  // C compiler if the project also compiles c sources
  // defaults to 'cc'
  "cc": "cc",
  // c sources if the project also compiles c sources
  // relative to the project file
  "c-sources": [
    "csource/**"
  ]
}

kcvinker avatar Feb 16 '24 12:02 kcvinker

Hmm.. that one looks normal. What if you just compile a single file with c3c.exe compile foo.c3?

lerno avatar Feb 16 '24 13:02 lerno

Let me check that.

kcvinker avatar Feb 16 '24 13:02 kcvinker

@lerno Same result. This is source.

import std::io;
fn void main()
{
	io::println("testing version 0.5.4");
}

And this is result

λ c3c compile foo.c3
1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math_random.c3:3:11) Error: 'Random' would shadow a previous declaration.

1: module std::math::random;
2:
3: interface Random
             ^^^^^^
(C:/Compilers/C3/lib/std/math/math.random.c3:3:11) Note: The previous use of 'Random' was here.

11:     fn void next_bytes(char[] buffer);
12: }
13:
14: macro bool is_random(random) => $assignable(random, Random*);
               ^^^^^^^^^
(C:/Compilers/C3/lib/std/math/math_random.c3:14:12) Error: 'is_random' would shadow a previous declaration.

kcvinker avatar Feb 16 '24 13:02 kcvinker

@lerno I think this issue is not caused by c3. I think I can do something. Let me try.

kcvinker avatar Feb 16 '24 13:02 kcvinker

@lerno, Yeah, it was a mistake from my side and I solved it. What caused the issue ---> I am using a python script to update the compilers I use in my projects. This script will download the latest binaries from github and extract them. Then it will remove the old files and paste the new files in respective directories. Last day, when you told me to check the version 0.5.4, I ran this script and at that time newest binaries where not uploaded to the repo's asset section. So my script ran and showed me an error message that there is no new files in the repo. After 2 hours, you uploaded the files and I ran this script again. This time everything worked smoothly and I got the version 0.5.4 installed. But something strange were happened when last time the script ran. I don't know what was it. But now, I copy pasted the new binaries with my hand, everything works smoothly.

kcvinker avatar Feb 16 '24 14:02 kcvinker

I wonder how it can be reproduced. Because that should never really be possible, incorrect libraries or not....

lerno avatar Feb 16 '24 14:02 lerno

I think we can reproduce. Steps

  1. run updater script when same version is available on github.
  2. run updater again when the new version available on github later.
  3. run c3 file now. It might bring the same error report.

kcvinker avatar Feb 16 '24 15:02 kcvinker

Ok, I know why now. Look at the file names:

C:/Compilers/C3/lib/std/math/math_random.c3:3:11) Error:
C:/Compilers/C3/lib/std/math/math.random.c3:3:11) Note 

Do you see the subtle difference? math_random.c3 and math.random.c3. Both ended up in lib/std/math because your just copied updated files in your script, you didn't delete the old stdlib files. So when names change, this happens.

lerno avatar Feb 16 '24 15:02 lerno

That's a clever observation. Your attention to detail and problem-solving skills are really impressive.

kcvinker avatar Feb 16 '24 15:02 kcvinker

Just ordinary debugging.

lerno avatar Feb 16 '24 19:02 lerno

can this issue be closed then?

goyalyashpal avatar Feb 25 '24 07:02 goyalyashpal

@goyalyashpal, Actually, the header file generation is still the same. It is not fixed yet.

kcvinker avatar Feb 25 '24 11:02 kcvinker

@kcvinker this is odd, can you show me some sample of the output. Because this was changed.

lerno avatar Feb 25 '24 23:02 lerno

@lerno This is my c3c version

C3 Compiler Version (alpha):       0.5.4
Installed directory:               C:/Compilers/C3/
LLVM version:                      16.0.2
LLVM default target:               x86_64-pc-windows-msvc

And this is the types generated by c3c in the header file.

typedef struct pyc3.Button__ pyc3.Button;
typedef struct pyc3.Control__ pyc3.Control;
typedef enum pyc3.ControlType__ pyc3.ControlType;
enum pyc3.ControlType__
{
	 pyc3.ControlType_NONE,
	 pyc3.ControlType_BUTTON,
	 pyc3.ControlType_CALENDAR,
	 pyc3.ControlType_CHECK_BOX,
	 pyc3.ControlType_COMBO_BOX,
	 pyc3.ControlType_DATE_TIME_PICKER,
	 pyc3.ControlType_GROUP_BOX,
	 pyc3.ControlType_LABEL,
	 pyc3.ControlType_LIST_BOX,
	 pyc3.ControlType_LIST_VIEW,
	 pyc3.ControlType_NUM_PICKER,
	 pyc3.ControlType_PROGRESS_BAR,
	 pyc3.ControlType_RADIO_BUTTON,
	 pyc3.ControlType_TEXT_BOX,
	 pyc3.ControlType_TRACK_BAR,
	 pyc3.ControlType_TREE_VIEW,
};

kcvinker avatar Feb 26 '24 11:02 kcvinker

@kcvinker You can use @export on your types to name them correctly.

cbuttner avatar Feb 26 '24 13:02 cbuttner

@cbuttner Let me try that. Thanks.

kcvinker avatar Feb 26 '24 14:02 kcvinker