Hi,
I'm on a M4 Mac, and I need custom LDFLAGS to find the verilator and systemc libraries.
I was unable to link, but changing
shell g++ --shared $v_objs $v_lib -pthread -lpthread -o $soname
to
shell g++ $LDFLAGS --shared $v_objs $v_lib -pthread -lpthread -o $soname
Fixed the problem.
Interesting, what did you need to add? It has been building for some time on M1 here without problems. (A sub-build of "Build others".) I would add this, but LDFLAGS seems too generic and liable to use a value set for something else. .IVLNG_LDFLAGS perhaps?
Edit: my mistake, that is for Icarus, not Verilator. While the Verilator support was tested on Mac, that was using X86.
Last edit: Giles Atkinson 2025-04-13
Seems like it was only this part of my LDFLAGS that was necessary to get the script to work
export LDFLAGS=" -undefined dynamic_lookup ${LDFLAGS}"
Strange, there should be no undefined symbols in the library. But I think I have seen something similar before.
I am inclined to fix this by including that option in the script, but would first like to know more. Without the option, what is the error message?
Thanks, G.
I have just compiled pre-master-45, using script compile_macos_clang_M2.sh, on a mac mini, M2, Sonoma 14.5 (23F79), without any problem.
The problem occurred in the script, vlnggen, so the way to reproduce this is to try an example circuit in examples/xspice/verilator.
G.
Rather long log, so adding as attachment
I got the "-undefined dynamic_lookup" from https://github.com/verilator/verilator/issues/3283#issuecomment-1017972747
Verilator declares sc_time_stamp() as a weak symbol. It means the user may optionally define it. Linux ld tolerates a missing weak symbol, macOS ld doesn't. The shim (verilator_shim.cpp) never actually calls sc_time_stamp() (time is driven via VerilatedContext::time()), so adding an empty stub there (attached patch) satisfies macOS ld without any vlnggen change.
Does the original suggestion of adding a linker option work for you? It is in the parallel ghnggen script, and seems harmless there.
The linker option approach works for me too. My patch was an attempt to address the problem without touching linker options, but if ghnggen already handles it that way, doing the same in vlnggen seems fine. I didn't know about ghnggen.
Thank you for testing. In fact the Verilator documentation does mention this issue (in the FAQ!) and recommends " -CFLAGS -DVL_TIME_CONTEXT". That will be in the update, as it solves the same problem on Windows, What I do not understand, is why this issue did not show up in initial testing of Verilator integration. The weak symbol was introduced in 2021, two years earlier.
Fix committed as [1ff2ae].
Related
Commit: [1ff2ae]