#Unable to find C files.

1 messages · Page 1 of 1 (latest)

tribal pagoda
#

When importing a C source like this in my build.zig:

const libremidi_translated = b.addTranslateC(.{
        .root_source_file = b.path("libremidi/include/libremidi/libremidi.hpp"),
        .optimize = optimize,
        .target = target,
    });
    const libremidi_translated_module = libremidi_translated.createModule();

and including it as a module via adding it to .imports of my exe like this: .{ .name = "libremidi", .module = libremidi_translated_module },
i get this error when compiling:

error: translation failure
libremidi\include\libremidi\libremidi.hpp:60:10: error: 'libremidi/api.hpp' not found
#include <libremidi/api.hpp>

I suspect i must provide include path for Zig to discover these missing source files. How do i do that?

#

Forgot to mention: all of these files are located in the same folder as my initial source file.

tribal pagoda
tribal pagoda
# fallow hill <https://ziglang.org/documentation/master/std/#std.Build.Step.TranslateC.addIncl...

compilation still fails with the same error somehow. Here's what i did:

    const libremidi_translated = b.addTranslateC(.{
        .root_source_file = b.path("libremidi/include/libremidi/libremidi.hpp"),
        .optimize = optimize,
        .target = target,
    });

    libremidi_translated.addIncludePath(b.path("./libremidi/include/libremidi/"));

    const libremidi_translated_module = libremidi_translated.createModule();

i also tried variations of the path, like removing the dot, adding the slash, removing the slash, and every variation of the above, just to be safe, cus windows paths are like that sometimes. I also re-checked whether i'm pointing at the correct folder. I am. Files are there. Have you seen something like this?

fallow hill
tribal pagoda
fallow hill
# tribal pagoda Why did it work?

because #include <libremidi/api.hpp>, ie what was happening was
./libremidi/include/libremidi/ + libremidi/api.hpp
== ./libremidi/include/libremidi/libremidi/api.hpp

tribal pagoda
fallow hill
tribal pagoda
tribal pagoda
# fallow hill cache errors => delete local cache and retry (no guarantees)

I ended up using libremidi.cpp, cus libremidi-c.h does not expose any symbols for me. Using cpp libremidi gives me this error:

error: 'vector' not found
  #include <vector>

naturally, i begin to search for where to give zig libcpp includes on my machine. Tried to provide it with Microsoft Visual Studio\2022\Community\VC\Tools\MSVC ones, but obviously, clang can't compile that.
I actually thought zig shipped with its own libc and libcpp.

hollow berry
tribal pagoda
hollow berry
tribal pagoda
# hollow berry what do you mean by "no symbols getting exposed to linker"

I have a .h header. (libremidi-c.h to be exact.) In it, a symbol is defined like this:

LIBREMIDI_EXPORT
const char* libremidi_get_version(void);

Among others.
I correctly compile my program with this header, but the moment i try to use it like this:

const libremidi = @import("libremidi");
...
const testt = libremidi.libremidi_get_version();
std.debug.print("{any}", .{testt});

, this error gets thrown:

error: lld-link: undefined symbol: libremidi_get_version
hollow berry
#

that's because you're not linking against the library

#

all you did is translated its headers

#

that's library's public api

tribal pagoda
#

Thanks. I'll be trying

hollow berry
#

unless the directory is in PATH on windows /LD_LIBRARY_PATH on other systems

tribal pagoda
#

At first, i'll be trying to add C sources directly. Then, if that fails, i'll just like the compiled library

hollow berry