Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Inline::C with MSVC and linking external library

by rem45acp (Novice)
on Aug 30, 2013 at 14:04 UTC ( #1051636=perlquestion: print w/replies, xml ) Need Help??
rem45acp has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I would like to be able to link to and use some functions from a C library, using Inline::C. The C library was compiled with Microsoft's compiler, so therefore I'm stuck using MSVC instead of gcc/mingw. What I'm having trouble with is that the compile process somewhere deep down in Inline can't properly link to the library. The platform is Windows XP. To make things easier, I placed the include file and lib file in the same directory as the perl script. I am using Visual Studio's command prompt to help sort out some environment variables, and also added the paths of MSVC's include files and libs to environment variables. For some reason it can't link to the library. Perl script:
use Inline C => Config => LIBS => '-usbi2cio.lib', BUILD_NOISY => 1; use Inline C => << 'END_C'; #include <windows.h> #include "Usbi2cio.h" void greet() { HANDLE h = DAPI_OpenDeviceInstance("UsbI2cIo", 0); printf("Hello, world\n"); } END_C greet;
Output from Inline:
validate Stage Starting Build Preprocess Stage get_maps Stage Finished Build Preprocess Stage Starting Build Parse Stage Finished Build Parse Stage Starting Build Glue 1 Stage Finished Build Glue 1 Stage Starting Build Glue 2 Stage Finished Build Glue 2 Stage Starting Build Glue 3 Stage Finished Build Glue 3 Stage Starting Build Compile Stage Starting "perl Makefile.PL" Stage Note (probably harmless): No library found for -usbi2cio.lib Writing Makefile for inline_c_pl_c65f Writing MYMETA.yml and MYMETA.json Finished "perl Makefile.PL" Stage Starting "make" Stage Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. C:\Perl\bin\perl.exe C:\Perl\lib\ExtUtils\xsubpp -typemap "C: +\Perl\lib\ExtUtils\typemap" i nline_c_pl_c65f.xs > inline_c_pl_c65f.xsc && C:\Perl\bin\perl.exe -MEx +tUtils::Command -e mv -- inlin e_c_pl_c65f.xsc inline_c_pl_c65f.c cl -c -I"C:/sandbox" -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -D +WIN32 -D_CONSOLE -DNO_STRICT - DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DP +ERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -MD -Zi -DNDEBUG -O1 -DVERSION=\"0.00\" -DXS_V +ERSION=\"0.00\" "-IC:\Perl\li b\CORE" inline_c_pl_c65f.c inline_c_pl_c65f.c Running Mkbootstrap for inline_c_pl_c65f () C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod -- 644 inlin C:\Perl\bin\perl.exe -MExtUtils::Mksymlists -e "Mksymlists('N +AME'=>\"inline_c_pl_c65f\", 'D LBASE' => 'inline_c_pl_c65f', 'DL_FUNCS' => { }, 'FUNCLIST' => [], 'I +MPORTS' => { }, 'DL_VARS' => []);" link -out:blib\arch\auto\inline_c_pl_c65f\inline_c_pl_c65f.dll + -dll -nologo -nodefaultlib -d ebug -opt:ref,icf -libpath:"C:\Perl\lib\CORE" -machine:x86 inline_c_ +pl_c65f.obj C:\Perl\lib\CORE \perl516.lib "C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB\oldn +ames.lib" "C:\Program Files\Mi crosoft SDKs\Windows\v6.0A\lib\kernel32.lib" "C:\Program Files\Microso +ft SDKs\Windows\v6.0A\lib\user 32.lib" "C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib\gdi32.lib" +"C:\Program Files\Microsoft SD Ks\Windows\v6.0A\lib\winspool.lib" "C:\Program Files\Microsoft SDKs\Wi +ndows\v6.0A\lib\comdlg32.lib" "C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib\advapi32.lib" "C:\P +rogram Files\Microsoft SDKs\Wi ndows\v6.0A\lib\shell32.lib" "C:\Program Files\Microsoft SDKs\Windows\ +v6.0A\lib\ole32.lib" "C:\Progr am Files\Microsoft SDKs\Windows\v6.0A\lib\oleaut32.lib" "C:\Program Fi +les\Microsoft SDKs\Windows\v6. 0A\lib\netapi32.lib" "C:\Program Files\Microsoft SDKs\Windows\v6.0A\li +b\uuid.lib" "C:\Program Files\ Microsoft SDKs\Windows\v6.0A\lib\ws2_32.lib" "C:\Program Files\Microso +ft SDKs\Windows\v6.0A\lib\mpr. lib" "C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib\winmm.lib" "C: +\Program Files\Microsoft SDKs\ Windows\v6.0A\lib\version.lib" "C:\Program Files\Microsoft SDKs\Window +s\v6.0A\lib\odbc32.lib" "C:\Pr ogram Files\Microsoft SDKs\Windows\v6.0A\lib\odbccp32.lib" "C:\Program + Files\Microsoft SDKs\Windows\ v6.0A\lib\comctl32.lib" "C:\Program Files\Microsoft Visual Studio 9.0\ +VC\LIB\msvcrt.lib" -def:inline _c_pl_c65f.def Creating library blib\arch\auto\inline_c_pl_c65f\inline_c_pl_c65f.l +ib and object blib\arch\auto\i nline_c_pl_c65f\inline_c_pl_c65f.exp inline_c_pl_c65f.obj : error LNK2019: unresolved external symbol _DAPI +_OpenDeviceInstance@8 referenc ed in function _greet blib\arch\auto\inline_c_pl_c65f\inline_c_pl_c65f.dll : fatal error LNK +1120: 1 unresolved externals NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio +9.0\VC\BIN\link.EXE"' : return code '0x460' Stop. A problem was encountered while attempting to compile and install your + Inline C code. The command that failed was: C:\PROGRA~1\MICROS~1.0\VC\BIN\nmake.exe The build directory was: C:\sandbox\_Inline\build\inline_c_pl_c65f To debug the problem, cd to the build directory, and inspect the outpu +t files. at C:\sandbox\ line 4. ...propagated at C:/Perl/site/lib/Inline/ line 772. BEGIN failed--compilation aborted at C:\sandbox\ line 14.
perl -V:
Summary of my perl5 (revision 5 version 16 subversion 3) configuration +: Platform: osname=MSWin32, osvers=5.2, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D +_CONSOLE -DNO_STRICT -DPERL_TE XTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPL +ICIT_SYS -DUSE_PERLIO -D_USE_3 2BIT_TIME_T', optimize='-MD -Zi -DNDEBUG -O1', cppflags='-DWIN32' ccversion='15.0.21022', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64 +', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -l +ibpath:"C:\Perl\lib\CORE" -ma chine:x86' libpth=\lib libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib +comdlg32.lib advapi32.lib shel l32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.l +ib winmm.lib version.lib odbc 32.lib odbccp32.lib comctl32.lib msvcrt.lib perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.l +ib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib m +pr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl516.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt: +ref,icf -libpath:"C:\Perl\lib \CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB +_ALLOC USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF USE_SITECUSTOMIZE Locally applied patches: ActivePerl Build 1603 [296746] Built under MSWin32 Compiled at Mar 13 2013 11:29:21 @INC: C:/Perl/site/lib C:/Perl/lib .

Replies are listed 'Best First'.
Re: Inline::C with MSVC and linking external library
by BrowserUk (Pope) on Aug 30, 2013 at 14:43 UTC

    Is your library really called: -usbi2cio.lib?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yes, the file name is usbi2cio.lib. It is a driver for an I2C board. And according to the Inline::C documentation, the dash goes in front?

        No. That parameter is basically the command line switch for the compiler to link the named library, -l and then the library name:

        use Inline C => Config => LIBS => '-lyourlib';

        So, in your case, I would try

        use Inline C => Config => LIBS => '-lusbi2cio';

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1051636]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2017-02-26 08:15 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.