TypeScriptCompiler icon indicating copy to clipboard operation
TypeScriptCompiler copied to clipboard

Library import issue

Open Sinfolke opened this issue 7 months ago • 7 comments

I'm sorry that there is already so much issues. There's another one that the compiler adds one more '_' to the functions it searches in static .lib library. I did write a bit some String class static properties on C and test them in ts. When it links it adds one more '_' (i understood it by the error message):

// ...
declare function __cfromCharsCode(numN: Reference<char>, count: i64): cst_string;
declare function __cfromCodePoint(numN: Reference<char>, count: u64): cst_string;
declare function __cadd_pointer(pointer: Reference<char>, value: int): Reference<char>;
// ...
EXPORT void* __cadd_pointer(void* ptr, int val) {
    return ptr + val;
}
EXPORT struct cst_string __cfromCharCode(const uint16_t* numN, const long long count) {
 // ...
}
EXPORT struct cst_string __cfromCodePoint(const uint32_t* numN, size_t count) {
// ...
}

as you may see there're two '__'. then compile:

C:\programming\tsc>clang -c -O3 native.c -o native.o
native.c:42:12: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
   42 |     memcpy(r.str, numN, r.len - 1);
      |            ^~~~~
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\vcruntime_string.h:44:41: note:
      passing argument to parameter '_Dst' here
   44 |     _Out_writes_bytes_all_(_Size) void* _Dst,
      |                                         ^
native.c:70:11: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
   70 |     char* ptr = r.str;
      |           ^     ~~~~~
native.c:99:18: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
   99 |             free(r.str);
      |                  ^~~~~
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_malloc.h:90:42: note: passing argument to
      parameter '_Block' here
   90 |     _Pre_maybenull_ _Post_invalid_ void* _Block
      |                                          ^
native.c:108:32: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers
      [-Wincompatible-pointer-types-discards-qualifiers]
  108 |         char* newstr = realloc(r.str, r.len);
      |                                ^~~~~
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_malloc.h:127:43: note: passing argument to
      parameter '_Block' here
  127 |     _Pre_maybenull_ _Post_invalid_ void*  _Block,
      |                                           ^
4 warnings generated.

C:\programming\tsc>llvm-ar rcs native.lib native.o

C:\programming\tsc>tsc.exe --lib=native --emit=exe test.ts -o test.exe
 "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.39.33519\\bin\\Hostx64\\x64\\link.exe" -out:test.exe -defaultlib:oldnames "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.39.33519\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.39.33519\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\um\\x64" -nologo "C:\\Users\\Admin\\AppData\\Local\\Temp\\test-791fce.obj" native.lib user32.lib msvcrtd.lib gcmt-lib.lib TypeScriptAsyncRuntime.lib LLVMSupport.lib
msvcrtd.lib(initializers.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
test-791fce.obj : error LNK2019: unresolved external symbol ___cadd_pointer referenced in function cst_string_to_string
test-791fce.obj : error LNK2019: unresolved external symbol ___cfromCharCode referenced in function String.fromCharCode
test-791fce.obj : error LNK2019: unresolved external symbol ___cfromCodePoint referenced in function String.fromCodePoint
test.exe : fatal error LNK1120: 3 unresolved externals
tsc: error: linker command failed with exit code 1120 (use -v to see invocation)

require 3 '___'. But if i use 3 '___' in C code and 2 '___' in ts it works

Sinfolke avatar Jul 25 '24 14:07 Sinfolke