odin-lang / odin-lang.org

http://odin-lang.org
22 stars 81 forks source link

Linker Error when using libc and raylib #152

Closed FrancisTheCat closed 11 months ago

FrancisTheCat commented 11 months ago

I recently tried to use a libc function while also using raylib, but when using a libc procedure, compilation fails with these errors:

ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005: fclose already defined in libucrt.lib(fclose.obj)
ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005: __stdio_common_vsprintf already defined in libucrt.lib(output.obj)
ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll) : error LNK2005: _errno already defined in libucrt.lib(errno.obj)
ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll) : error LNK2005: exit already defined in libucrt.lib(exit.obj)
ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005: __acrt_iob_func already defined in libucrt.lib(_file.obj)
ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005: fflush already defined in libucrt.lib(fflush.obj)
ucrt.lib(api-ms-win-crt-stdio-l1-1-0.dll) : error LNK2005: __stdio_common_vfprintf already defined in libucrt.lib(output.obj)
libucrt.lib(argv_data.obj) : error LNK2005: __p___argc already defined in ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll)
libucrt.lib(argv_data.obj) : error LNK2005: __p___argv already defined in ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll)
libucrt.lib(environment_initialization.obj) : error LNK2005: _get_initial_narrow_environment already defined in ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll)
libucrt.lib(environment_initialization.obj) : error LNK2005: _initialize_narrow_environment already defined in ucrt.lib(api-ms-win-crt-runtime-l1-1-0.dll)
C:\Dev\odin\raylibc\raylibc.exe : fatal error LNK1169: one or more multiply defined symbols found
package raylibc

import "core:c/libc"
import "vendor:raylib"

main :: proc() {
    raylib.InitWindow(400, 400, "test")
    defer raylib.CloseWindow()
    libc.system("echo hello")
}
FrancisTheCat commented 11 months ago

Im dumb this is the website repo lol, similar issue in the right repo by someone else already

Kelimion commented 11 months ago

@FrancisTheCat Meanwhile, here's what you can do on Windows to sidestep the issue:

import win32 "core:sys/windows"

copy_file :: proc(from_path, to_path: string, overwrite_if_exists := true) -> (ok: bool) {
    defer free_all(context.temp_allocator)
    _from_path := win32.utf8_to_wstring(from_path, context.temp_allocator)
    _to_path   := win32.utf8_to_wstring(to_path,   context.temp_allocator)

    return bool(win32.CopyFileW(_from_path, _to_path, bFailIfExists=!overwrite_if_exists))

}

main :: proc() {
    success := copy_file("My.dll", "My.dll.bak")
    fmt.printf("Copy 'My.dll' to 'My.dll.bak': %v\n", success)
}