Skip to content

Conflicting raylib and libc Windows libraries #2796

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

Closed
deadwanderer opened this issue Sep 11, 2023 · 2 comments
Closed

Conflicting raylib and libc Windows libraries #2796

deadwanderer opened this issue Sep 11, 2023 · 2 comments
Labels

Comments

@deadwanderer
Copy link
Contributor

deadwanderer commented Sep 11, 2023

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:
  • Please paste odin report output:

Odin: dev-2023-08-nightly:9453b238
OS: Windows 10 Enterprise (version: 22H2), build 19045.3324
CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
RAM: 32662 MiB

Expected Behavior

No linker multiple defines errors when using libc with raylib

Current Behavior

What is the current behavior?

Failure Information (for bugs)

When I attempt to use core:c/libc and vendor:raylib at the same time, I get a number of linker errors when compiling:

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-heap-l1-1-0.dll) : error LNK2005: calloc already defined in libucrt.lib(calloc.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: system already defined in libucrt.lib(system.obj)
ucrt.lib(api-ms-win-crt-filesystem-l1-1-0.dll) : error LNK2005: _access already defined in libucrt.lib(access.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)
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(matherr.obj) : error LNK2005: __setusermatherr already defined in ucrt.lib(api-ms-win-crt-math-l1-1-0.dll)

It appears that raylib uses ucrt.lib (I couldn't find an explicit CRT load in raylib's code), and libc pulls in libucrt.lib. When I replaced libucrt.lib with ucrt.lib in my Odin installation's core:c/libc files, the issue went away, and I was able to compile without issues (at least for the small subset of both Raylib and libc that I'm currently using :-) )

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

I use raylib for windowing and graphics, and am attempting to hot-reload a dll. I use libc.system() to copy and delete the DLL before loading and after rebuilding, respectively. Using both these libraries together causes the above linker errors.

Failure Logs

Please include any relevant log snippets or files here.

@github-actions github-actions bot added the stale label Jan 9, 2024
@laytan
Copy link
Collaborator

laytan commented Apr 4, 2024

#3307 is an attempt at fixing this

@nawetimebomb
Copy link

nawetimebomb commented Jun 9, 2024

Hey, I solved this issue by not using libc and doing the copy and delete through sys/windows.

import "core:sys/windows";
import "core:unicode/utf16";

To copy:

    current_filename_buf, new_filename_buf : [64]u16;
    utf16.encode_string(current_filename_buf[:], "game.dll");
    utf16.encode_string(new_filename_buf[:], dll_name);

    if !windows.CopyFileW(raw_data(current_filename_buf[:]), raw_data(new_filename_buf[:]), false) {
        // success
    }

To delete:

    filename_buf : [64]u16;
    utf16.encode_string(filename_buf[:], dll_to_delete);

    if windows.DeleteFileW(raw_data(filename_buf[:])) {
        // success
    }

Note: I'm sharing this solution because I noticed #3307 has some discussions about this topic and it might not get merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants