Skip to content

Use of 'strtok_r' fails in Windows #92

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

Closed
gabe565 opened this issue Dec 20, 2015 · 9 comments · Fixed by #105
Closed

Use of 'strtok_r' fails in Windows #92

gabe565 opened this issue Dec 20, 2015 · 9 comments · Fixed by #105

Comments

@gabe565
Copy link

gabe565 commented Dec 20, 2015

I come across this error when trying to compile on Windows. I have MSYS2 installed (I used the rust guide that is linked in the tutorial). It seems that 'strtok_r' is not supported by MSYS2.

error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-static-libgcc" "-m64" "-L" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\hello_world.0.o" "-o" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\hello_world.exe" "-Wl,--gc-sections" "-L" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug" "-L" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps" "-L" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\build\\curl-sys-c7834bee3e6a49e1\\out/lib" "-L" "C:/msys64/mingw64/lib" "-L" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib" "-L" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\.rust\\bin\\x86_64-pc-windows-gnu" "-L" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\bin\\x86_64-pc-windows-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libcurl-cc078f6df50d4b80.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\liburl-9145034d63069ffd.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\liblog-db195e915b7f1b50.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libcurl_sys-c7834bee3e6a49e1.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libuuid-82ee95c4f525f1f6.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\librustc_serialize-7ff5bfc027146194.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libmatches-68291f81832fc22d.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\librand-204b49f864ff4762.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libadvapi32-cfef7a1f30f1e5f6.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\libwinapi-d88a8c018c340227.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\liblibz_sys-521f51dd8fade4c2.rlib" "C:\\Users\\User\\Documents\\eclipse\\workspace\\test\\target\\debug\\deps\\liblibc-53b3109cf33a6ace.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcollections-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_unicode-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\librand-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc_jemalloc-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\liblibc-35c36e89.rlib" "C:\\Program Files\\Rust stable 1.5\\bin\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcore-35c36e89.rlib" "-l" "ws2_32" "-l" "advapi32" "-l" "z" "-l" "ws2_32" "-l" "userenv" "-l" "advapi32" "-l" "compiler-rt"
note: C:\Users\User\Documents\eclipse\workspace\test\target\debug\deps\libcurl_sys-c7834bee3e6a49e1.rlib(libcurl_la-cookie.o):cookie.c:(.text$Curl_cookie_add+0xc5): undefined reference to `strtok_r'
C:\Users\User\Documents\eclipse\workspace\test\target\debug\deps\libcurl_sys-c7834bee3e6a49e1.rlib(libcurl_la-cookie.o):cookie.c:(.text$Curl_cookie_add+0x13a): undefined reference to `strtok_r'
ld: C:\Users\User\Documents\eclipse\workspace\test\target\debug\deps\libcurl_sys-c7834bee3e6a49e1.rlib(libcurl_la-cookie.o): bad reloc address 0x13a in section `.text$Curl_cookie_add'
ld: final link failed: Invalid operation

Could there be something I missed in my install?
I cannot find much about this error online except that this function is not on Windows.

@pvginkel
Copy link

The problem is that the gcc version bundled with Rust does not define strtok_r, and the MinGW version does. The solution is to change the installation of Rust to not install the bundled gcc. If you re-run the setup; choose "Change", click the drop down before "Linker and platform libraries" and choose "The entire feature will be unavailable", the compilation should work.

@alexcrichton
Copy link
Owner

I tracked this down awhile ago and unfortunately the problem is:

  • libcurl is compiling with the system gcc and is detecting a newer feature, the strtok_r function.
  • When the compiler links the crate, it uses a bundled gcc version
  • This bundled gcc version uses its own libraries, which don't have the detected function.

Unfortunately the only fix here is to just delete the bundled linker that comes with Rust (or uncheck the box during the install).

@masaeedu
Copy link

@alexcrichton What is the equivalent to "unchecking the box during install" for installs with rustup?

@alexcrichton
Copy link
Owner

@masaeedu unfortunately I don't know of a great way to do that. My personal way to work around this is to always install the MSVC host toolchain and then target pc-windows-gnu, that way these components aren't picked up

@masaeedu
Copy link

@alexcrichton I've also tried the MSVC toolchain, but this package seems to break with that as well, with the following error message:

Couldn't find libcurl from pkgconfig ("MSVC target detected. If you are using the MSVC ABI rust build, please use the GNU ABI build instead."), compiling it from source...

I'm trying to install https://github.com/killercup/cargo-edit, which depends on curl, using cargo install cargo-edit. If I use the GNU toolchain via rustup default stable-gnu, I get the strtok_r issue. If I use the MSVC toolchain via rustup default stable-msvc I get the message I pasted above. Any ideas on how to proceed are greatly appreciated.

@alexcrichton
Copy link
Owner

@masaeedu that looks more like an informational message than an error maybe? Could you gist the full build log?

@masaeedu
Copy link

@alexcrichton
Copy link
Owner

Oh the actual build there is:

curl_setup.h(132): fatal error C1083: Cannot open include file: 'curl/curlbuild.h': No such file or directory

That's building an ancient version of curl-sys though (0.1.*) which has had tons of bug fixes since then. Unfortunately though it doesn't look like you control the version being used :(

@masaeedu
Copy link

I guess cargo-edit's depending on an old version of curl, which in turn pulls in an old version of curl-sys. I'll go file a bug there. Thanks.

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