Hermanverschooten

Hermanverschooten

Undefined symbol when using zigler and C file

This my first time using zig and zigler.

I am trying to use the embedded library for wireguard.
I have in the same folder, wireguard.h, wireguard.c and wireguard.ex.
The Wireguard module has

defmodule Wireguard do
  use Zig,
    otp_ap: :wg_man,
    c_src: [{"wireguard.c", ["-Wall"]}],
    include_dir: "."

  ~Z"""
  const std = @import("std");
  const crypto = std.crypto;
  const log = std.log.scoped(.wireguard);

  const wireguard = @cImport({
    @cInclude("wireguard.h");
  });

  pub fn list_devices() void {
    var deviceNames: [*c]u8 = null;
 
   deviceNames = wireguard.wg_list_device_names() orelse null;

    defer std.c.free(@ptrCast(?*anyopaque, deviceNames));

    if (deviceNames == null) {
        log.err("Unable to get device names", .{});
        return;
    }
  }
  """

When I try to mix compile, I get the following error:

== Compilation error in file lib/wireguard/wireguard.ex ==
** (MatchError) no match of right hand side value: ["error: ld.lld: undefined symbol: wg_list_device_names\n    note: referenced by .Elixir.Wireguard.zig:13 (/home/herman/Projects/wg_man/lib/wireguard/.Elixir.Wireguard.zig:13)\n    note:               /home/herman/.cache/zig/o/f3cd82336c77b73ffaead67d9007ba46/sema.o:(.Elixir.Wireguard.list_devices)"]
    (zigler 0.10.2) lib/zig/compile_error.ex:11: Zig.CompileError.to_error/2
    (zigler 0.10.2) lib/zig/sema.ex:88: Zig.Sema.run_sema!/3
    (zigler 0.10.2) lib/zig/compiler.ex:76: Zig.Compiler.compile/4
    (zigler 0.10.2) expanding macro: Zig.Compiler.__before_compile__/1
    lib/wireguard/wireguard.ex:1: Wireguard (module)

This function is defined in wireguard.c, so why is it not being found?
If I remove the body from the zig function it compiles and when I look at the exported functions in the generated Elixir.Wireguard.so I do find all the functions there.
I am probably missing something, but I have no clue where to start looking.

Marked As Solved

ityonemo

ityonemo

@Hermanverschooten should be fixed in 0.10.3, feel free to reopen bug report if it doesn’t work.

Also Liked

ityonemo

ityonemo

this is a bug in zigler. I think i know how to fix it, thanks for the report.

Hermanverschooten

Hermanverschooten

@ityonemo Yes! It works, thanks for the fantastic job!

Where Next?

Popular in Questions Top

Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

We're in Beta

About us Mission Statement