-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Undefined symbols re: src/compat/compat.h when linking statically #2454
Comments
ok so just to make sure i understand, you're trying to link an application to the notcurses static library on macOS, and that's where you see this output? |
btw i've been unable to get on |
Very sorry about that, will take a look right away. |
It should be accessible now, can you give it a try? |
yep, we good, thanks! |
I see similar output on Linux, macOS, and Windows when trying to use static linking in the context of compiling a program with the Nim compiler. Here's how it goes on macOS:
Gives this output:
So then I run the clang command with
And I get:
Next I run the ld command with
Yielding:
|
A similar exercise, with appropriately adjusted It could very well be that the problem is related to how I'm using nimterop with my nim-notcurses wrapper, which is responsible for downloading and cmake+make'ing notcurses. The nimterop approach does work with the notcurses shared library, so maybe there's any extra step/option/something I've missed for static linking. Anyway, this could be a problem only on my end, or it may be something to do with notcurses itself. I'm just not sure, and after a lot of poking around, I felt stuck so thought to get some extra eyeballs on it. Thanks for at least taking a look; if you're confident the problem is on my end, I'll see if I can get the nimterop maintainers to take a look also. |
i've no insights yet; i'm totally unlettered regarding Nim. i'm gonna try to look at this tonight or tomorrow, but no promises. |
Thanks! And sure, I understand you're not familiar with Nim. Maybe I/we could create a minimal kind of example involving static linking and notcurses that doesn't involve Nim, just a simple If that works, then it's likely a problem with how I'm presently mis/using nimterop. |
I admit this is harder for me than I'd like to admit as I had no real exposure to C/C++ until after I started working with Nim, going on 2 years ago, so there's just a lot I don't know or understand and/or misunderstand. |
so those symbols oughtn't be getting exported, but they ought be getting built into the libraries that call them. strange. |
i was definitely able to get a static compile working just now with
|
Thanks for the tip re: using #include <notcurses/notcurses.h>
int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_NO_ALTERNATE_SCREEN |
NCOPTION_PRESERVE_CURSOR |
NCOPTION_NO_CLEAR_BITMAPS |
NCOPTION_DRAIN_INPUT,
};
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}
notcurses_render(nc);
notcurses_stop(nc);
return EXIT_SUCCESS;
} On macOS, with notcurses v3.0.0 installed with homebrew, when I do:
It works, but it's definitely not performing static linking:
The What I want to do is (I think) more like this:
But that gives me the following error, complaining about the same symbols re:
|
doh i'm retarded; we needed a |
So one I thing I happen to know about is that Apple for years now has actively un-supported static linking to In practice what that means is that you can static link to everything else you want (e.g. stuff from homebrew), but the core runtime stuff (not sure if that's the correct terminology, but in any case it's Now, in practice, I have in the past successfully built executables that were statically linked to everything but Or maybe not if you're saying you get the same blowup with |
[schwarzgerat](1) $ gcc -pthread --static -o cli2-static cli2.c libnotcurses.a libnotcurses-core.a /usr/lib/x86_64-linux-gnu/libtinfo.a /usr/lib/x86_64-linux-gnu/libdeflate.a
/usr/bin/ld: libnotcurses-core.a(util.c.o): in function `notcurses_accountname':
/home/dank/src/dankamongmen/notcurses/src/lib/util.c:42: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: libnotcurses-core.a(notcurses.c.o): in function `utf8_egc_len':
/home/dank/src/dankamongmen/notcurses/src/lib/egcpool.h:110: undefined reference to `uc_is_grapheme_break'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/egcpool.h:114: undefined reference to `uc_is_property_variation_selector'
/usr/bin/ld: libnotcurses-core.a(notcurses.c.o): in function `notcurses_ucs32_to_utf8':
/home/dank/src/dankamongmen/notcurses/src/lib/notcurses.c:3198: undefined reference to `u32_to_u8'
/usr/bin/ld: /tmp/cc6yOnRy.o: in function `main':
cli2.c:(.text+0x6b): undefined reference to `notcurses_render'
/usr/bin/ld: libnotcurses-core.a(direct.c.o): in function `utf8_egc_len':
/home/dank/src/dankamongmen/notcurses/src/lib/egcpool.h:110: undefined reference to `uc_is_grapheme_break'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/egcpool.h:114: undefined reference to `uc_is_property_variation_selector'
/usr/bin/ld: libnotcurses-core.a(in.c.o): in function `create_inputctx':
/home/dank/src/dankamongmen/notcurses/src/lib/in.c:1610: undefined reference to `pthread_condmonotonic_init'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/in.c:1612: undefined reference to `pthread_condmonotonic_init'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/in.c:1619: undefined reference to `set_fd_nonblocking'
/usr/bin/ld: libnotcurses-core.a(in.c.o): in function `stop_inputlayer':
/home/dank/src/dankamongmen/notcurses/src/lib/in.c:2290: undefined reference to `set_fd_nonblocking'
/usr/bin/ld: libnotcurses-core.a(visual.c.o): in function `ncvisual_rotate':
/home/dank/src/dankamongmen/notcurses/src/lib/visual.c:707: undefined reference to `sin'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/visual.c:708: undefined reference to `cos'
/usr/bin/ld: libnotcurses-core.a(fd.c.o): in function `launch_pipe_process':
/home/dank/src/dankamongmen/notcurses/src/lib/fd.c:233: undefined reference to `set_fd_nonblocking'
/usr/bin/ld: libnotcurses-core.a(metric.c.o): in function `ncnmetric':
/home/dank/src/dankamongmen/notcurses/src/lib/metric.c:29: undefined reference to `fesetround'
collect2: error: ld returned 1 exit status
[schwarzgerat](1) $ ok, this seems to be pretty much what you're running into, yeah? |
[schwarzgerat](1) $ gcc -pthread --static -o cli2-static cli2.c libnotcurses.a libnotcurses-core.a /usr/lib/x86_64-linux-gnu/libtinfo.a /usr/lib/x86_64-linux-gnu/libdeflate.a /usr/lib/x86_64-linux-gnu/libunistring.a /usr/lib/x86_64-linux-gnu/libm.a
/usr/bin/ld: libnotcurses-core.a(util.c.o): in function `notcurses_accountname':
/home/dank/src/dankamongmen/notcurses/src/lib/util.c:42: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/ccuiEev9.o: in function `main':
cli2.c:(.text+0x6b): undefined reference to `notcurses_render'
/usr/bin/ld: libnotcurses-core.a(in.c.o): in function `create_inputctx':
/home/dank/src/dankamongmen/notcurses/src/lib/in.c:1610: undefined reference to `pthread_condmonotonic_init'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/in.c:1612: undefined reference to `pthread_condmonotonic_init'
/usr/bin/ld: /home/dank/src/dankamongmen/notcurses/src/lib/in.c:1619: undefined reference to `set_fd_nonblocking'
/usr/bin/ld: libnotcurses-core.a(in.c.o): in function `stop_inputlayer':
/home/dank/src/dankamongmen/notcurses/src/lib/in.c:2290: undefined reference to `set_fd_nonblocking'
/usr/bin/ld: libnotcurses-core.a(fd.c.o): in function `launch_pipe_process':
/home/dank/src/dankamongmen/notcurses/src/lib/fd.c:233: undefined reference to `set_fd_nonblocking'
collect2: error: ld returned 1 exit status
[schwarzgerat](1) $ ahhh thar we go |
fix incoming |
hrmmm, no, surprising, that didn't get it... |
should be fixed |
[schwarzgerat](0) $ gcc -D_XOPEN_SOURCE=500 -I../include -pthread --static -o cli2-static cli2.c libnotcurses.a libnotcurses-core.a /usr/lib/x86_64-linux-gnu/libtinfo.a /usr/lib/x86_64-linux-gnu/libdeflate.a /usr/lib/x86_64-linux-gnu/libunistring.a /usr/lib/x86_64-linux-gnu/libm.a
/usr/bin/ld: libnotcurses-core.a(util.c.o): in function `notcurses_accountname':
/home/dank/src/dankamongmen/notcurses/src/lib/util.c:42: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
[schwarzgerat](0) $ |
we just weren't compiling the compat.c into the static library, dumb. i need to add a target that links up statically so we verify that this keeps working. also, all of that crap you're having to list ought be getting put into the pkg-confg file, i would think. |
Awesome, thanks for taking a look and for finding such a quick fix. I'll give it a spin tomorrow, for sure.
That would be nice, though I think I was running into some problems with pkg-config on mac and windows; I'll give that another look tomorrow, may have been user error on my part. |
The changes you made re: "compiling the compat.c into the static library" worked great, thanks! There are some troubles with pkg-config re: static linking, on macOS at least, that will require more thought on my part... or I may need to give up on my "nimterop + static linking" approach now that I'm learning more of the pitfalls, i.e. simply rely on notcurses to have been installed with apt or brew or whatever and link to it as a shared library. |
yeah, i came to the same conclusion. all that manual listing of libraries oughtn't be necessary. i intend to look into this. |
Not long after I posted the discussion nim-notcurses: a wrapper..., it got difficult for me to make time for it, but I'm excited to try again. 🙂
In that discussion I asked a question about static linking, and you made a recommendation re:
pkg-config
. That was helpful re: Linux, but not so much for macOS and Windows. However, that's another issue/s which can be discussed separately.I've worked out this kind of thing re: static linking to
libnotcurses-core.a
on macOS:And I've worked out similar on Linux and Windows.
However, in all cases, static linking ultimately fails with something like this (this paste is from macOS):
After poking around, I found the undefined symbols correspond to declarations in
src/compat/compat.h
.I did some naive experiments like adding this near the top of
compat.h
:And prefixing e.g.
pthread_condmonotonic_init
withAPI extern
. But that didn't work.Any ideas as to whether there's something I may be doing wrong re: how I'm linking statically, or whether there may need to be some adjustments to notcurses'
CMakeLists.txt
or one/more of its headers?The text was updated successfully, but these errors were encountered: