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

libjpeg-turbo fails to compile on 32bit MSVC #111

Closed
benjamin-otte opened this issue Jul 16, 2021 · 7 comments · Fixed by #112
Closed

libjpeg-turbo fails to compile on 32bit MSVC #111

benjamin-otte opened this issue Jul 16, 2021 · 7 comments · Fixed by #112

Comments

@benjamin-otte
Copy link

Running the GTK compile with the MSVC 2019 32bit toolchain (apparently I was opening the wrong shortcut and got that one) failed with:

[1986/3743] Linking target subprojects/libjpeg-turbo-2.1.0/jpeg-8.2.2.dll
FAILED: subprojects/libjpeg-turbo-2.1.0/jpeg-8.2.2.dll subprojects/libjpeg-turbo
-2.1.0/jpeg-8.2.2.pdb
"link" @subprojects/libjpeg-turbo-2.1.0/jpeg-8.2.2.dll.rsp
   Creating library subprojects\libjpeg-turbo-2.1.0\jpeg.lib and object subproje
cts\libjpeg-turbo-2.1.0\jpeg.exp
jcphuff.c.obj : error LNK2019: unresolved external symbol ___builtin_ctzl refere
nced in function _count_zeroes
subprojects\libjpeg-turbo-2.1.0\jpeg-8.2.2.dll : fatal error LNK1120: 1 unresolv
ed externals
[1987/3743] Linking target subprojects...pixbuf/gdk-pixbuf/pixops/timescale.exe
ninja: build stopped: subcommand failed.

After trying to debug it a bit, it seems to be that there's a not just the check for ___builtin_ctzl but also one for sizeof(long)==sizeof(size_t) and that 2nd check fails on 64bit but not on 32bit, so ___builtin_ctzl gets disabled on the CI boxes because of that.

@eli-schwartz
Copy link
Member

It should be checking that the __builtin_ctzl is functional:

code = 'int main(int argc, char **argv) { unsigned long a = argc; return __builtin_ctzl(a); }'
cdata.set('HAVE_BUILTIN_CTZL', cc.compiles(code))

Apparently on MSVC this does compile (both in the meson check, and in jcphuff.c.obj), but does not link? Is this somehow available on MSVC, but needs an additional library?

@tp-m
Copy link
Member

tp-m commented Jul 16, 2021

I can confirm this fails to link on MSVC for x86. The only reason it "works" on x64 is that the check is bypassed entirely because of the size checks.

I think the best / correct thing to do here is to just do cc.has_function('__builtin_ctzl')? (Which works correctly).

I don't know why it compiles though, I'm not aware of these builtins being available on MSVC, they've got their own builtins for that (_BitScan*) as far as I know.

@xclaesse
Copy link
Member

xclaesse commented Jul 16, 2021

FWIW, that's a direct translation from cmake:

if(SIZE_T EQUAL UNSIGNED_LONG)
  check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc;  return __builtin_ctzl(a); }"
    HAVE_BUILTIN_CTZL)
endif()

But... the cmake doc actually says:

Check that the source supplied in <code> can be compiled as a C source file and linked as an executable

So cc.links() is probably a better test here.

xclaesse added a commit to xclaesse/wrapdb that referenced this issue Jul 16, 2021
This is a translation from CMake's check_c_source_compiles() that
compiles and links the code.

Fixes: mesonbuild#111
@tp-m
Copy link
Member

tp-m commented Jul 16, 2021

Not convinced it's "better", but whatever works ;)

@xclaesse
Copy link
Member

If someone can give it a try: #112

@xclaesse
Copy link
Member

Not convinced it's "better", but whatever works ;)

I mean, closer to what cmake does, which is the reference here.

xclaesse added a commit to xclaesse/wrapdb that referenced this issue Jul 16, 2021
This is a translation from CMake's check_c_source_compiles() that
compiles and links the code.

Fixes: mesonbuild#111
xclaesse added a commit to xclaesse/wrapdb that referenced this issue Jul 16, 2021
This is a translation from CMake's check_c_source_compiles() that
compiles and links the code.

Fixes: mesonbuild#111
@eli-schwartz
Copy link
Member

Does it need to be a reference to cmake? I agree that it makes more sense to use has_function, and it should be faster too.

xclaesse added a commit to xclaesse/wrapdb that referenced this issue Jul 16, 2021
This is a translation from CMake's check_c_source_compiles() that
compiles and links the code.

Fixes: mesonbuild#111
jpakkane pushed a commit that referenced this issue Jul 25, 2021
This is a translation from CMake's check_c_source_compiles() that
compiles and links the code.

Fixes: #111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants