Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Can't call libcurl with Inline::C on Windows

by Anonymous Monk
on Nov 18, 2019 at 09:49 UTC ( #11108859=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I've downloaded libcurl for windows but my test script is failed:
use strict; use warnings; use Inline 'Config' => BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0; use Inline 'C' => 'Config' => libs => '-LC:\Users\Administrator\Downlo +ads\curl-7.67.0_4-win64-mingw\curl-7.67.0-win64-mingw\lib -lcurl', inc => '-IC:\Users\Administrator\Downloads\curl-7. +67.0_4-win64-mingw\curl-7.67.0-win64-mingw\include'; use Inline 'C' => <<'CODE'; #include <errno.h> #include <stdlib.h> #include <string.h> #ifndef WIN32 #include <unistd.h> #endif #include <curl/curl.h> int init(){ CURLM *cm; curl_global_init(CURL_GLOBAL_WIN32); return 0; } CODE
output:
g++.exe bb_pl_d714.def -o blib\arch\auto\bb_pl_d714\bb_pl_d714.xs.dll +-mdll -s -L"C:\perl\perl\lib\CORE" -L"C:\perl\c\li b" bb_pl_d714.o "C:\perl\perl\lib\CORE\libperl530.a" "C:\perl\perl\s +ite\lib\auto\share\dist\Alien-curl\lib\libcurl.a" "C:\perl\c\x86_64-w64-mingw32\lib\libmoldname.a" "C:\perl\c\x86_64-w64 +-mingw32\lib\libkernel32.a" "C:\perl\c\x86_64-w64- mingw32\lib\libuser32.a" "C:\perl\c\x86_64-w64-mingw32\lib\libgdi32.a" + "C:\perl\c\x86_64-w64-mingw32\lib\libwinspool.a" "C:\perl\c\x86_64-w64-mingw32\lib\libcomdlg32.a" "C:\perl\c\x86_64-w64 +-mingw32\lib\libadvapi32.a" "C:\perl\c\x86_64-w64- mingw32\lib\libshell32.a" "C:\perl\c\x86_64-w64-mingw32\lib\libole32.a +" "C:\perl\c\x86_64-w64-mingw32\lib\liboleaut32.a" "C:\perl\c\x86_64-w64-mingw32\lib\libnetapi32.a" "C:\perl\c\x86_64-w6 +4-mingw32\lib\libuuid.a" "C:\perl\c\x86_64-w64-min gw32\lib\libws2_32.a" "C:\perl\c\x86_64-w64-mingw32\lib\libmpr.a" "C:\ +perl\c\x86_64-w64-mingw32\lib\libwinmm.a" "C:\perl \c\x86_64-w64-mingw32\lib\libversion.a" "C:\perl\c\x86_64-w64-mingw32\ +lib\libodbc32.a" "C:\perl\c\x86_64-w64-mingw32\lib \libodbccp32.a" "C:\perl\c\x86_64-w64-mingw32\lib\libcomctl32.a" -Wl,- +-enable-auto-image-base C:/perl/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w +64-mingw32/bin/ld.exe: bb_pl_d714.o:bb_pl_d714.c:( .text+0x6a): undefined reference to `__imp_curl_global_init' C:/perl/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w +64-mingw32/bin/ld.exe: bb_pl_d714.o:bb_pl_d714.c:( .text+0x11b): undefined reference to `__imp_curl_global_init' collect2.exe: error: ld returned 1 exit status gmake: *** [Makefile:475: blib\arch\auto\bb_pl_d714\bb_pl_d714.xs.dll] + Error 1 A problem was encountered while attempting to compile and install your + Inline C code. The command that failed was: "gmake" with error code 2 The build directory was: C:\perl\_Inline\build\bb_pl_d714 To debug the problem, cd to the build directory, and inspect the outpu +t files. at bb.pl line 6. ...propagated at C:/perl/perl/site/lib/Inline/C.pm line 888. BEGIN failed--compilation aborted at bb.pl line 6.
perl -V:
C:\perl>perl -V Summary of my perl5 (revision 5 version 30 subversion 0) configuration +: Platform: osname=MSWin32 osvers=10.0.17763.529 archname=MSWin32-x64-multi-thread uname='Win32 strawberry-perl 5.30.0.1 #1 Thu May 23 12:20:46 2019 +x64' config_args='undef' hint=recommended useposix=true d_sigaction=undef useithreads=define usemultiplicity=define use64bitint=define use64bitall=undef uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='gcc' ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANS +I_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CO NTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -m +ms-bitfields' optimize='-s -O2' cppflags='-DWIN32' ccversion='' gccversion='8.3.0' gccosandvers='' intsize=4 longsize=4 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long long' ivsize=8 nvtype='double' nvsize=8 Off_t='long long' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='g++.exe' ldflags ='-s -L"C:\perl\perl\lib\CORE" -L"C:\perl\c\lib"' libpth=C:\perl\c\lib C:\perl\c\x86_64-w64-mingw32\lib C:\perl\c\li +b\gcc\x86_64-w64-mingw32\8.3.0 libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 + -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi3 2 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl +32 perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomd +lg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnet api32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lco +mctl32 libc= so=dll useshrplib=true libperl=libperl530.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs dlext=xs.dll d_dlsymun=undef ccdlflags=' ' cccdlflags=' ' lddlflags='-mdll -s -L"C:\perl\perl\lib\CORE" -L"C:\perl\c\lib"' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF Built under MSWin32 Compiled at May 23 2019 12:26:54 @INC: C:/perl/perl/site/lib/MSWin32-x64-multi-thread C:/perl/perl/site/lib C:/perl/perl/vendor/lib C:/perl/perl/lib
Any ideas ? Thanks in advance!

Replies are listed 'Best First'.
Re: Can't call libcurl with Inline::C on Windows
by ikegami (Pope) on Nov 18, 2019 at 15:53 UTC

    Note that Net::Curl already provides bindings for that library.

      No,Net:::Curl is only for Linux.
        Net:::Curl is only for Linux

        I've successfully built Net-Curl-0.37 on Windows in the past (for perls 5.8.8 through to 5.24.x).
        I haven't checked to see whether there's a later version of Net-Curl, and I haven't bothered building it on later versions of perl.
        I can see that I had to hack the Makefile.PL a bit (I could provide details if there's any interest), and I also needed the following patch to Curl.xs:
        --- Curl.xs_orig 2015-06-22 19:33:33 +1000 +++ Curl.xs 2015-06-22 19:51:00 +1000 @@ -17,6 +17,15 @@ #include "perl.h" #include "XSUB.h" +#ifdef __MINGW32__ +#undef fread +#undef fwrite +#endif + #include <curl/curl.h> #include <curl/easy.h> #include <curl/multi.h>
        Not so sure that it passed its test suite entirely, but it was certainly generally usable.

        Cheers,
        Rob
Re: Can't call libcurl with Inline::C on Windows
by Anonymous Monk on Nov 18, 2019 at 11:10 UTC
      Thanks! I link to libcurl.dll.a, Inline can build a xs.dll successfully. but still failed:
      "C:\perl\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- +bb_pl_d714.bs blib\arch\auto\bb_pl_d714\bb_pl_d714.bs 644 Files found in blib\arch: installing files in blib\lib into architectu +re dependent library tree Installing C:\Users\Administrator\Downloads\curl-7.67.0_4-win64-mingw\ +curl-7.67.0-win64-mingw\_Inline\lib\auto\bb_pl_d714\bb_pl_d714.xs.dll Finished "make install" Stage Starting Cleaning Up Stage Finished Cleaning Up Stage Finished Build Compile Stage Had problems bootstrapping Inline module 'bb_pl_d714' Can't load 'C:\Users\Administrator\Downloads\curl-7.67.0_4-win64-mingw +\curl-7.67.0-win64-mingw\_Inline\lib/auto/bb_pl_d714/bb_pl_d714.xs.dl +l' for module bb_pl_d714: load_file:The specified module could not be found a +t C:/perl/perl/lib/DynaLoader.pm line 193. at C:/perl/perl/site/lib/Inline.pm line 541. at bb.pl line 6. BEGIN failed--compilation aborted at bb.pl line 6.
        Had problems bootstrapping Inline module 'bb_pl_d714'

        I think you simply need to add the location of the libcurl dll to your PATH, as that dll needs to be located at runtime.
        That location is probably:
        C:\Users\Administrator\Downloads\curl-7.67.0_4-win64-mingw\curl-7.67.0 +-win64-mingw\bin
        This script (almost identical to yours) worked fine for me on Windows, building against curl-7.65.0-2, as provided by the MSYS2 project:
        use strict; use warnings; use Inline 'Config' => BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0; use Inline 'C' => 'Config' => libs => '-LC:\_64\msys64\mingw64\lib -lc +url.dll', inc => '-IC:\_64\msys64\mingw64\\include'; use Inline 'C' => <<'CODE'; #include <errno.h> #include <stdlib.h> #include <string.h> #ifndef WIN32 #include <unistd.h> #endif #include <curl/curl.h> int init(){ CURLM *cm; curl_global_init(CURL_GLOBAL_WIN32); printf("SUCCESS !!\n"); return 0; } CODE init();
        After the build completed it output "SUCCESS !!".

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11108859]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2021-10-20 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (81 votes). Check out past polls.

    Notices?