Closed smac89 closed 5 months ago
This is indeed a bug, and has to do with on_test
and package:check_cxxsnippets
.
check_cxxsnippets
does not produce the correct compile command. Given the above snippet, it tries to execute this command:
/usr/bin/g++ -o /tmp/.xmake1000/240401/_82EDF1BAE8414A10880A19FFAB1D9D20.b /tmp/.xmake1000/240401/_82EDF1BAE8414A10880A19FFAB1D9D20.o -m64 -L/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e/lib -L/home/user/.local/share/xmake/packages/g/glad/v0.1.36/dd6f7de88060486a93ea896ea2b462ea/lib -L/usr/lib -lstb_hello_imgui -limgui -lhello_imgui -llunasvg -lglad -lSDL2 -lfreetype -lz -ldl
Notice the lack of a .cpp
file anywhere in the command? It doesn't include the source file
.
I was able to fix the issue with check_cxxsnippets, by specifying the linking order for the library. I had to add the following add_linkorders("hello_imgui", "stb_hello_imgui", "imgui")
to the package file
For now, I've decided to ignore the snippet issue and settled for a simpler test:
assert(package:has_cxxincludes("hello_imgui/hello_imgui.h"))
Which works
Originally posted by @smac89 in https://github.com/xmake-io/xmake/discussions/4919#discussioncomment-8977528
please add add_links("hello_imgui", "stb_hello_imgui", "imgui")
in your package configuration.
If you don't configure any links, xmake will automatically walk the lib directory when the package is installed and get all the library files to set the links, but their linking order is undefined. If there is a dependency order between several sub-libraries of the package, configure them explicitly via add_links.
It has nothing to do with on_test and is not a bug.
libfiles = { "/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e/lib/libstb_hello_imgui.a", "/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e/lib/libimgui.a", "/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e/lib/libhello_imgui.a", "/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e/lib/liblunasvg.a" }
please add
add_links("hello_imgui", "stb_hello_imgui", "imgui")
in your package configuration.
@waruqi would that still be necessary even after using add_linkorders("hello_imgui", "stb_hello_imgui", "imgui")
?
Everything seems to be linking properly after adding that line. This also means the test is passing.
Also, the reason I say on_test
has a bug is because the installed package is deleted if the on_test
test fails. I don't see this documented anywhere, and I don't think this is something people will easily catch. In my case at least, I didn't, and it took me a while of debugging to figure out that the reason the apparently installed package no longer exists in the install directory is because the test failed, and xmake just deletes it.
If you don't see it as a bug or think it's intuitive enough, I would go ahead and close this issue.
would that still be necessary even after using
add_linkorders("hello_imgui", "stb_hello_imgui", "imgui")
?
you need only add_links, please remove add_linkorders
I created this package xmake file for
hello-imgui
:The package file for
imgui-src
is defined simply as:When I build the
hello-imgui
package, everything looks good, and I even see this towards the end:However, at the end I get the following error:
I investigated this issue for some time yesterday, and discovered that the package
installdir
(/home/user/.local/share/xmake/packages/h/hello-imgui/v1.4.2/3867d18f39804217a9828d5ad141028e
) was actually never created or was deleted right after the installation. In any case, it doesn't exist, which could explain why the linker is having a hard time finding what it needs.Any help would be appreciated
Originally posted by @smac89 in https://github.com/xmake-io/xmake/discussions/4919