float.h not found or included properly when using mingw-w64 - c++

I'm trying to cross-compile a piece of code which uses float.h to set some FPU sizes.
The particular piece of code that requires it is:
#ifdef SINGLE
_control87(_PC_24, _MCW_PC); /* Set FPU control word for single precision. */
#else /* not SINGLE */
_control87(_PC_53, _MCW_PC); /* Set FPU control word for double precision. */
#endif /* not SINGLE */
When I compile, however, I get the error
/home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.c:4922:14: error: '_PC_53' undeclared (first use in this function)
_control87(_PC_53, _MCW_PC); /* Set FPU control word for double precision. */
Another person explains what seems to be the same problem in more detail here. There is also a very similar issue described in a (rather old) thread here. In case it's relevant, I'm using mingw-w64, but via the M Cross Environment
What exactly is the problem with float.h in this case, and is there a workaround?
EDIT: Verbose output from gcc
Using built-in specs.
COLLECT_GCC=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-gcc
Target: x86_64-w64-mingw32.shared
Configured with: /opt/mxe/tmp-gcc-x86_64-w64-mingw32.shared/gcc-4.9.4/configure --target=x86_64-w64-mingw32.shared --build=x86_64-unknown-linux-gnu --prefix=/opt/mxe/usr --libdir=/opt/mxe/usr/lib --enable-languages=c,c++,objc,fortran --enable-version-specific-runtime-libs --with-gcc --with-gnu-ld --with-gnu-as --disable-nls --disable-multilib --without-x --disable-win32-registry --enable-threads=win32 --enable-libgomp --with-gmp=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-isl=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-mpc=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-mpfr=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-cloog=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-as=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-as --with-ld=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-ld --with-nm=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-nm
Thread model: win32
gcc version 4.9.4 (GCC)
COLLECT_GCC_OPTIONS='-c' '-I' '../cfemm/fmesher' '-I' '../cfemm/libfemm' '-I' '../cfemm/libfemm/liblua' '-I' '/usr/local/MATLAB/R2015a/extern/include' '-I' '/usr/local/MATLAB/R2015a/simulink/include' '-D' 'MATLAB_MEX_FILE' '-std=c99' '-D' '_GNU_SOURCE' '-fexceptions' '-fPIC' '-fno-omit-frame-pointer' '-pthread' '-v' '-fpermissive' '-D' 'CPU86' '-D' 'MX_COMPAT_32' '-O' '-D' 'NDEBUG' '-o' '/home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.o' '-mtune=generic' '-march=x86-64'
/opt/mxe/usr/libexec/gcc/x86_64-w64-mingw32.shared/4.9.4/cc1 -quiet -v -I ../cfemm/fmesher -I ../cfemm/libfemm -I ../cfemm/libfemm/liblua -I /usr/local/MATLAB/R2015a/extern/include -I /usr/local/MATLAB/R2015a/simulink/include -D_REENTRANT -U_REENTRANT -D MATLAB_MEX_FILE -D _GNU_SOURCE -D CPU86 -D MX_COMPAT_32 -D NDEBUG /home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.c -quiet -dumpbase triangle.c -mtune=generic -march=x86-64 -auxbase-strip /home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.o -O -std=c99 -version -fexceptions -fPIC -fno-omit-frame-pointer -fpermissive -o /tmp/ccMkwwWD.s
cc1: warning: command line option '-fpermissive' is valid for C++/ObjC++ but not for C
GNU C (GCC) version 4.9.4 (x86_64-w64-mingw32.shared)
compiled by GNU C version 4.8.4, GMP version 6.1.1, MPFR version 3.1.4, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/../../../../x86_64-w64-mingw32.shared/sys-include"
#include "..." search starts here:
#include <...> search starts here:
../cfemm/fmesher
../cfemm/libfemm
../cfemm/libfemm/liblua
/usr/local/MATLAB/R2015a/extern/include
/usr/local/MATLAB/R2015a/simulink/include
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/include
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/include-fixed
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/../../../../x86_64-w64-mingw32.shared/include
End of search list.
EDIT: more info
I also get the same result if I use the full directory path to the mingw-w64 float.h like so:
//#include <float.h>
#include "/opt/mxe/usr/x86_64-w64-mingw32.static/include/float.h"
EDIT more info on code structure
To give some further information, I am actually compiling C library (header and C file) where declaration of the function I'm using is included using extern C. The actual declaration from the header file is shown below:
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ANSI_DECLARATORS
int triangulate(char *, struct triangulateio *, struct triangulateio *,
struct triangulateio *, int (*TriMessage)(const char * format, ...));
void trifree(VOID *memptr);
#else /* not ANSI_DECLARATORS */
int triangulate();
void trifree();
#endif /* not ANSI_DECLARATORS */
#ifdef __cplusplus
}
#endif
The actual library I'm using is Triangle. The float.h include is in triangle.c, and looks like this:
#ifdef CPU86
//#include <float.h>
#include "/opt/mxe/usr/x86_64-w64-mingw32.static/include/float.h"
#endif /* CPU86 */
#ifdef LINUX
#include <fpu_control.h>
#endif /* LINUX */
Where you define CPU86 or LINUX at compile time. For the cross build, I'm defining CPU86.

OK, after some searching around I found this in triangle.c:
/* On some machines, my exact arithmetic routines might be defeated by the */
/* use of internal extended precision floating-point registers. The best */
/* way to solve this problem is to set the floating-point registers to use */
/* single or double precision internally. On 80x86 processors, this may */
/* be accomplished by setting the CPU86 symbol for the Microsoft C */
/* compiler, or the LINUX symbol for the gcc compiler running on Linux. */
/* */
Note that it says "On 80x86 processors". The host you're compiling for - windows 64 bit (x86_64) - does not match that.
This is further supported by the official documentation from Microsoft about the extension that's used by the library you're trying to compile:
Mask
_MCW_PC (Precision control)
(Not supported on ARM or x64 platforms.)
[..]
_PC_24 (24 bits)
_PC_53 (53 bits)
_PC_64 (64 bits)
[..]
Thus I guess you need to configure your build differently, probably not defining CPU86. Though I don't know whether this really solves your issue, or just leads to wrong results. After all ... is this library even ported to 64 bit?

Related

Can I use CLang and libstdc++ (emmintrin.h)

The following code
#include <iostream>
int main(void)
{
std::cout << "Hello World!" << std::endl;
return 0;
}
compiles fine with both g++ and clang
g++ test.cpp
clang -I /usr/lib/gcc/x86_64-linux-gnu/4.7/include -I /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed -lstdc++ test.cpp
where /usr/lib/gcc/x86_64-linux-gnu/4.7/ points to the include files of the libstdc++
However, when I add an additional #include <emmintrin.h>
the clang compilations fails with
In file included from test.cpp:2:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/include/emmintrin.h:36:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/include/xmmintrin.h:36:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/mmintrin.h:46:72: warning: unknown attribute '__artificial__' ignored [-Wunknown-attributes]
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
^
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/mmintrin.h:52:72: warning: unknown attribute '__artificial__' ignored [-Wunknown-attributes]
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
...
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/xmmintrin.h:120:19: error: use of undeclared identifier '__builtin_ia32_divss'; did you mean '__builtin_ia32_minss'?
return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B);
...
According to http://en.cppreference.com/w/cpp/header, the `xmmintrin.h' is not part of the interface of the standard C++ library and hence I guess it contains Gnu specific stuff. Can I somehow compile this code using clang?
If not, how can I easily install the clang libc++?
sudo aptitude install libc++-dev doesn't find a package (while this does work on Ubuntu 16.04)
I'm using
"Debian GNU/Linux 7 (wheezy)"
gcc version 4.7.2 (Debian 4.7.2-5) // Target: x86_64-linux-gnu
clang version 3.6.0 (trunk 224504) // Target: x86_64-unknown-linux-gnu
Apparently, my clang installation was incomplete.
After downloading llvm and clang (v3.7.1 since v4.0.1 required gcc4.8 while I only have 4.7) and building it locally clang -lstdc++ test.cpp works fine in both cases.

warning: 'assume_aligned' attribute directive ignored

I just started with C++ and i think the best way is to look at source codes. I have code as follows in the header file.
#ifdef _MSC_VER
#define MYAPP_CACHE_ALIGNED_RETURN /* not supported */
#else
#define MYAPP_CACHE_ALIGNED_RETURN __attribute__((assume_aligned(64)))
#endif
I am using gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) and its quite old. I get this warning during compilation:
warning: 'assume_aligned' attribute directiv e ignored [-Wattributes] –
How can I make the if statement more specific to fix the the warning during compilation?
It seems that assume_aligned is not supported in RHEL's GCC (it hasn't been backported to upstream gcc-4_8-branch and also not available in Ubuntu 14.04's GCC 4.8.4 so that wouldn't be surprising).
To emit a more user-friendly diagnostics you can do an explicit check for GCC version in one of your headers:
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)
# warning "Your version of GCC does not support 'assume_aligned' attribute"
#endif
But this may not work if your distro vendor has back-ported assume_aligned from upstream (which is not the case for RedHat and Ubuntu but who knows about other distros). The most robust way to check this would be to do a build-time test in configure script or in Makefile:
CFLAGS += $(shell echo 'void* my_alloc1() __attribute__((assume_aligned(16)));' | gcc -x c - -c -o /dev/null -Werror && echo -DHAS_ASSUME_ALIGNED)
This will add HAS_ASSUME_ALIGNED to predefined macro if the attribute is supported by compiler.
Note that you can achieve similar effect with __builtin_assume_aligned function:
void foo() {
double *p = func_that_misses_assume_align();
p = __builtin_assume_aligned(p, 128);
...
}

Header for _blsr_u64 with Sun supplied GCC on Solaris 11?

We've got some code that runs on multiple platforms. The code uses BMI/BMI2 intrinsics when available, like a Core i7 5th gen. GCC supplied by Sun on Solaris 11.3 is defining __BMI__ and __BMI2__, but its having trouble locating BMI/BMI2 intrinsics:
$ cat test.cxx
#include <x86intrin.h>
int main(int argc, char* argv[])
{
unsigned long long t = argc;
#if defined(__BMI__) || defined(__BMI2__)
t = _blsr_u64(t);
#endif
return int(t);
}
$ /bin/g++ -march=native test.cxx -o test.exe
test.cxx: In function ‘int main(int, char**)’:
test.cxx:6:18: error: ‘_blsr_u64’ was not declared in this scope
t = _blsr_u64(t);
^
Including immintrin.h does not make a difference.
Which header do we include for _blsr_u64 when using GCC on Solaris 11.3?
Here are the relevant defines from GCC:
$ /bin/g++ -march=native -dM -E - < /dev/null | sort | \
/usr/gnu/bin/egrep -i '(sse|aes|rdrnd|rdseed|avx|bmi)'
#define __AES__ 1
#define __AVX__ 1
#define __AVX2__ 1
#define __BMI__ 1
#define __BMI2__ 1
#define __core_avx2 1
#define __core_avx2__ 1
#define __RDRND__ 1
#define __RDSEED__ 1
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSSE3__ 1
#define __tune_core_avx2__ 1
And CPU features:
$ isainfo -v
64-bit amd64 applications
avx xsave pclmulqdq aes movbe sse4.2 sse4.1 ssse3 amd_lzcnt popcnt tscp
ahf cx16 sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu prfchw adx
rdseed efs rtm hle bmi2 avx2 bmi1 f16c fma rdrand
And GCC version:
$ /bin/g++ --version
g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
Which header do we include for _blsr_u64 when using GCC on Solaris 11.3?
It looks like #include <x86intrin.h> is correct.
The problem was the compiler invocation required both -march=native -m64 even though 64-bit is native for the machine and the kernel is 64-bit:
$ /bin/g++ -march=native -m64 test.cxx -o test.exe

C++ Compile error on NetBSD '::system' has not been declared

I have some C++ code that compiles nicely on Linux but so far I'm having trouble getting it to compile correctly on NetBSD.
These are my includes:
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <iomanip>
#include <boost/regex.hpp>
I compile with this command:
g++ -v -O2 -fno-strict-aliasing -I /usr/pkg/include \
barefoot.cpp -o barefoot -L /usr/pkg/lib/ -lboost_regex \
-L /usr/pkg/lib/ -lboost_regex -lpthreads
Which renders this output:
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64--netbsd
Configured with: /usr/src2/tools/gcc/../../external/gpl3/gcc/dist/configure --target=x86_64--netbsd --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb2 20111202' --enable-__cxa_atexit --with-tune=nocona --with-mpc=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --with-mpfr=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --with-gmp=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --enable-tls --disable-multilib --disable-symvers --disable-libstdcxx-pch --build=x86_64-unknown-netbsd5.99.56 --host=x86_64--netbsd
Thread model: posix
gcc version 4.5.3 (NetBSD nb2 20110806)
COLLECT_GCC_OPTIONS='-v' '-O2' '-fno-strict-aliasing' '-I' '/usr/pkg/include/' '-o' 'a.out' '-L' '/usr/pkg/lib/' '-mtune=nocona' '-march=x86-64'
/usr/libexec/cc1plus -quiet -v -I /usr/pkg/include/ barefoot.cpp -quiet -dumpbase barefoot.cpp -mtune=nocona -march=x86-64 -auxbase barefoot -O2 -version -fno-strict-aliasing -o /var/tmp//cc9Dcmwi.s
GNU C++ (NetBSD nb2 20110806) version 4.5.3 (x86_64--netbsd)
compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131007
#include "..." search starts here:
#include <...> search starts here:
/usr/pkg/include/
/usr/include/g++
/usr/include/g++/backward
/usr/include/gcc-4.5
/usr/include
End of search list.
GNU C++ (NetBSD nb2 20110806) version 4.5.3 (x86_64--netbsd)
compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131007
Compiler executable checksum: a34e7d170f4dd8d4687d2b62e8dca4b7
In file included from /usr/include/g++/bits/gthr.h:166:0,
from /usr/include/g++/ext/atomicity.h:34,
from /usr/include/g++/bits/ios_base.h:41,
from /usr/include/g++/ios:43,
from /usr/include/g++/istream:40,
from /usr/include/g++/fstream:40,
from barefoot.cpp:29:
/usr/include/g++/bits/gthr-default.h:130:9: error: 'pthread_detach' was not declared in this scope
/usr/include/g++/bits/gthr-default.h:130:1: error: invalid type in declaration before ';' token
/usr/include/g++/bits/gthr-default.h: In function 'int __gthread_detach(pthread_st*)':
/usr/include/g++/bits/gthr-default.h:668:46: error: '__gthrw_pthread_detach' cannot be used as a function
In file included from /usr/pkg/include/boost/regex/v4/regex_workaround.hpp:25:0,
from /usr/pkg/include/boost/regex/v4/regex.hpp:32,
from /usr/pkg/include/boost/regex.hpp:31,
from barefoot.cpp:32:
/usr/include/g++/cstdlib: At global scope:
/usr/include/g++/cstdlib:132:11: error: '::system' has not been declared
I tried adding -lpthread, but that resulted in the same output. Not sure what to try next.
I do not know exactly why you are facing this problem, but I can provide you with some next steps to try.
Notice that the first error is that pthread_detach is missing. The system header files will typically make sure whatever headers they need are included, but you can try adding <pthread.h> above all the other headers.
If that fails, you need to figure out which file got included as a result of adding #include <pthread.h>, and make sure pthread_detach is present inside it (it really should be there somewhere).
Assuming it is there, there must be some conditional compilation that is causing it to not be visible to your source code. Find the conditional guards, and what macro values affect it.
Then, you will need to see why your system is defining the macro values in a way that causes the function pthread_detach to not be visible.
With this investigation, you may discover that you are not including the right <pthread.h> file. This may be due to system include directories conflicting with the include directories you want to use.
This answer (it is towards the bottom) to this question shows how to display the predefined macros for the g++ compiler.

undefined reference to ‘_imp__InitBizLib’

I am getting the error above when trying to use a 3rd party SDK with a C++ program written using eclipse on XP. Based on searches I understand that this error is caused by the linker not correctly pointing to the .dll or .lib. I have included the path to these items in the Environmental Variable - PATH, and also in eclipse under Properties\C/C++ Build\Settings\MinGW C++ Linker\Libraries. The path used for both of these items is C:\Program Files\Card Scanning Solutions\SDK
Here is the console output:
**** Build of configuration Debug for project HelloWorld ****
**** Internal Builder is used for build ****
g++ -IC:\Program Files\Card Scanning Solutions\SDK -O0 -g3 -Wall -c -fmessage-length=0 -lm -v -o src\BizScan.o ..\src\BizScan.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.1/configure --enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/cc1plus.exe -quiet -v -I C:\Program Files\Card Scanning Solutions\SDK -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.6.1/ -dD ..\src\BizScan.cpp -quiet -dumpbase BizScan.cpp -mtune=i386 -march=i386 -auxbase-strip src\BizScan.o -g3 -O0 -Wall -version -fmessage-length=0 -o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.1/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\Card Scanning Solutions\SDK
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
Compiler executable checksum: 8e56a7b4b7f3db333ff95dd4b2d788a4
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/as.exe -o src\BizScan.o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
g++ -LC:\Program Files\Card Scanning Solutions\SDK -lm -o HelloWorld.exe src\HelloWorld.o src\BizScan.o
src\BizScan.o: In function `ZN7BizScan4InitEv':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:20: undefined reference to `_imp__UseFixedModel'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:22: undefined reference to `_imp__SetTwainScanner'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:23: undefined reference to `_imp__InitScanLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:27: undefined reference to `_imp__InitImageLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:31: undefined reference to `_imp__InitBizLib'
src\BizScan.o: In function `~BizScan':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:39: undefined reference to `_imp__UnInitScanLib'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 5648 ms.
Here is BizScan.cpp:
/*
* BizScan.cpp
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#include "BizScan.h"
#include "slibexp.h" // ScanLib SDK header file
#include "..\header_lib\BizExp.h" // ScanLib SDK header file
#include "..\header_lib\ImageExp.h" // ScanLib SDK header file
#include "CSSN.h"
#include "windef.h"
BizScan::BizScan() {
BizScan::Init();
}
const char* BizScan::Init() {
UseFixedModel(11);
const char *scannerSelected = "WIA-A6 Scanner 735";
int result = SetTwainScanner(scannerSelected);
result = InitScanLib(CSSN::GetSDKLicense().c_str());
if(result < 0 && result != -13){
return ScannerErrors(result);
} else {
result = InitImageLib(CSSN::GetSDKLicense().c_str());//initialize Image Lib SDK
if(result < 0 && result != -13)//if error
return ImageErrors(result);//call image lib sdk
result = InitBizLib(CSSN::GetSDKLicense().c_str());//initialize Biz Card Lib Scanner SDK
if(result < 0 && result != -13)//if error
return BizErrors(result);//call biz card scanner Lib SDK error handler
}
return "Successful Initialization !!";
}
BizScan::~BizScan() {
UnInitScanLib();
}
Here is BizScan.h:
/*
* BizScan.h
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#ifndef BIZSCAN_H_
#define BIZSCAN_H_
#include "windef.h"
typedef HINSTANCE hDLL;
class BizScan {
private:
public:
BizScan();
virtual ~BizScan();
const char* Init() ;
};
#endif /* BIZSCAN_H_ */
And here is the relevant part of slibexp.h:
/*/////////////////////////////////////////////////////////////////////
//
// SLibExp.h
//
// Card Scanning Solutions (LLC)
// All Rights Reserved
//
/////////////////////////////////////////////////////////////////////*/
#ifndef SLIBEXP_H
#define SLIBEXP_H
#ifdef SDLL
#define SDLL_EXP __declspec( dllexport )
#else
#define SDLL_EXP __declspec( dllimport )
#endif
// Functions Prototypes
#if defined __cplusplus || defined c_plusplus
extern "C"
{
#endif
SDLL_EXP void UseFixedModel(int val);
SDLL_EXP short SetTwainScanner(const char *szStr);
SDLL_EXP short InitScanLib(const char * license);
IMAGE_EXPORT short InitImageLib(const char *licanse);
SDLL_EXP short UnInitScanLib();
#if defined __cplusplus || defined c_plusplus
};
#endif
#endif /* SLIBEXP_H */
The other two methods, referenced in the console output both are defined in other header files that are in the same folder (the project root directory). These are defined as follows:
IMAGE_EXPORT short InitImageLib(const char *licanse);
extern "C" BIZ_EXPORT short InitBizLib(const char *license);
Is there another place I need to link these .dll's. I have tried using the LoadLibrary() method, but that method gets rejected for not being part of the scope. How should I link to these dll's? Thank you for any direction you may offer.
Looking at the output you show, this is the relevant command:
g++ -LC:\Program Files\Card Scanning Solutions\SDK -lm -o HelloWorld.exe src\HelloWorld.o src\BizScan.o
It includes the path to the library, but there is no reference ro the actual library itself. I don't know what the name of the library is, but let's assume it's libBizLib.a, there should be -lBizLib at the end of that command; or if you want to link against the dll, you can use its full name (without -l).
(By the way, you mention a .lib extension of the library. That usually indicates a Visual Studio library. Are you sure the version you have, is compatible with MinGW?)
A similar issue happened to me recently. It appears to be because of the difference in compilers. Where the library was built with one version of MinGW w64, my version is different enough that I can't compile in the .a file that came with the library.
But you can use dll's at runtime using LoadLibrary, but you then have to be more explicit when calling it. Then the main ways the dll won't load is if the file isn't in the dll load path or if the dll is the wrong bit type (32 bit v 64 bit).
Hope that helps.