Skip to content
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

Errors compiling minimal example: "undefined reference to pthread_create" and "undefined reference to `dlopen'" (and my fixes) #380

Closed
vindarel opened this issue May 31, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@vindarel
Copy link
Contributor

Hi,

Compiling webui worked instantly, but compiling the minimal example gave me these errors:

Build C Example (gcc release static)...
/usr/bin/ld: home/vince/lisp-projects/webui/examples/C/minimal//../../..//dist/libwebui-2-static.a(webui.o): in function `_webui_show_window':
webui.c:(.text+0x9c03): undefined reference to `pthread_create'
/usr/bin/ld: webui.c:(.text+0x9c0f): undefined reference to `pthread_detach'
/usr/bin/ld: webui.c:(.text+0x9daf): undefined reference to `pthread_create'
/usr/bin/ld: webui.c:(.text+0x9dbb): undefined reference to `pthread_detach'

[…]

/usr/bin/ld: /home/vince/lisp-projects/webui/examples/C/minimal//../../..//dist/libwebui-2-static.a(webui.o): in function `_webui_wv_show':
webui.c:(.text+0xce4e): undefined reference to `dlopen'
/usr/bin/ld: webui.c:(.text+0xcec6): undefined reference to `dlopen'
/usr/bin/ld: webui.c:(.text+0xcf1e): undefined reference to `dlsym'

I found a combinaison of characters in the Makefile that makes the compilation succeed and the example run:

# in examples/minimal/GNUMakefile
# BUILD FLAGS
# STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
STATIC_BUILD_FLAGS = main.c  -Wl,--no-as-needed -ldl  -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
# DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
DYN_BUILD_FLAGS = main.c  -Wl,--no-as-needed -ldl  -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"

[…]

else
	# STATIC_BUILD_FLAGS += -lpthread -lm -l$(WEBUI_LIB_NAME)-static
	STATIC_BUILD_FLAGS +=  -lm -l$(WEBUI_LIB_NAME)-static -lpthread
	# DYN_BUILD_FLAGS += -lpthread -lm
	DYN_BUILD_FLAGS += -lm -lpthread

-lpthread is moved last and I added -Wl,--no-as-needed -ldl (source: first SO answers).

minimal example: ./main runs but takes 100% CPU, ./main-dyn segfaults, both binaries of the text editor run.


I am on an oldish system:

Mint 20 LTS (Ubuntu Focal), x64
gcc 9.4.0


kuddos for the work.

@vindarel vindarel changed the title Errors compiling minimal example: "undefined reference to pthread_create" and "undefined reference to dlopen'" (and my fixes) Errors compiling minimal example: "undefined reference to pthread_create" and "undefined reference to `dlopen'" (and my fixes) May 31, 2024
@ttytm
Copy link
Member

ttytm commented May 31, 2024

This is on main/nightly right?

Likely a dup of #379

@vindarel
Copy link
Contributor Author

indeed, nightly branch, commit from May 28th a54d906 main origin/main nightly Fix GC WebView2.

@hassandraga
Copy link
Member

Fixed. Thank you for the report.

@vindarel
Copy link
Contributor Author

vindarel commented Jun 3, 2024

I pulled master ("4466bcf main origin/main Update webui_get_best_browser description") and I was having the same error messages when compiling the minimal example, but now I only need to add -Wl,--no-as-needed -ldl:

-STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
-DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
+STATIC_BUILD_FLAGS = main.c  -Wl,--no-as-needed -ldl  -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
+DYN_BUILD_FLAGS = main.c  -Wl,--no-as-needed -ldl  -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"

@hassandraga
Copy link
Member

hassandraga commented Jun 3, 2024

I see, after we added WebView dynamic load feature to WebUI 2.5.0 Beta 1, libdl (-ldl) should be added to all GNU's makefiles as well.

@hassandraga hassandraga reopened this Jun 3, 2024
@hassandraga hassandraga added the bug Something isn't working label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants