Closed MobSlicer152 closed 2 months ago
I'm curious, which compiler are you using? You said you use MSVC but MSVC doesn't have a prefix and already uses .lib extension.
As for this issue, xmake searches library based on the toolchain know lib extension, I think the best here is not to make a custom package but to make a custom toolchain (if msvc doesn't suit you)
I'm targetting the GDK, and I use a custom platform name with the msvc
toolchain from xmake, so basically the cross
platfrom, with msvc
. The cross
platform defaults to Linux naming, which MSVC doesn't like. I don't know why (I've dug through the code for installing packages and stuff) it doesn't link to the library, or why it only detects it with its default naming. Sorry, didn't see the second paragraph. There's no way to define a real custom platform that doesn't just get treated as cross
, or change the extension from the toolchain. I had previously been using custom targets within my code, but my old structure was messy and I was hoping I'd be able to get packages to work. I think if a way to define custom platforms was added, it would work fine. MSVC does work, it's just the code that detects libraries goes by extension of the file or something, and if you change it, then it's not detected, and there's not necessarily a good way to fix that for cross
.
This is how I do the gdk
platform I have:
-- This is in my project
set_allowedplats(
"gdk", "gdkx", "xbox360", "windows",
"linux",
"switch", "switchhb"
)
set_allowedarchs(
"gdk|x64", "gdkx|x64", "xbox360|powerpc64", "windows|x86",
"switch|arm64", "switchhb|arm64"
)
-- This is in a separate lua file that gets included and then called in a function I use for on_load
function fix_name(target)
if is_plat("gdk", "gdkx", "xbox360") then
target:set("prefixname", "")
if target:kind() == "binary" then
target:set("extension", ".exe")
elseif target:kind() == "static" then
target:set("extension", ".lib")
elseif target:kind() == "shared" then
target:set("extension", ".dll")
end
elseif is_plat("switch") then
if target:kind() == "binary" then
target:set("prefixname", "")
target:set("extension", ".nss")
elseif target:kind() == "static" then
target:set("prefixname", "lib")
target:set("extension", ".a")
elseif target:kind() == "shared" then
target:set("prefixname", "lib")
target:set("extension", ".nrs")
end
elseif is_plat("switchhb", "psp", "ps3") then
if target:kind() == "binary" then
target:set("prefixname", "")
target:set("extension", ".elf")
elseif target:kind() == "static" then
target:set("prefixname", "lib")
target:set("extension", ".a")
elseif target:kind() == "shared" then
target:set("prefixname", "lib")
target:set("extension", ".elf")
end
end
end
I also have a similar if
in the xmake.lua
for my mimalloc package, and it builds mimalloc_local.lib
fine, but it just doesn't know it's a library, so all it does is install it, but it's not available as a library when I do add_packages("mimalloc_local")
, and it doesn't even have an error, so it's basically like if I didn't link to the library.
The cross platform is only for cross-compilation toolchain, but msvc is not. If you still use msvc, please use windows platform.
And package only supports some builtin platforms now.
You can define a custom option to set your custom platform. e.g. option("myplat")
, xmake f --myplat=gdk
.
Xmake Version
v2.9.2+master.38c2ebc6f
Operating System Version and Architecture
Windows 10.0.19045.4529 Pro 22H2
Describe Bug
In my project, I use custom platforms which use MSVC, meaning the names have to follow the exact convention or they don't work. I get around this by setting the prefix and extension like this:
If the two lines there aren't commented out, when I build the package, no libraries are detected, and using
add_packages
only finds header files, even though the library output is still copied.Expected Behavior
When I change the extension of a target used in a package, it should still be detected as a library and included in the list for the package, so I can link to it.
Project Configuration
Additional Information and Error Logs
With the default cross name:
With the custom name: