eclipse - Windows C++ __imp reference error when building -
environment:
- windows server 2012 r2
- eclipse luna
- cygwin
- mingw
i building c++ program queries against active directory using ldap (similar msdn page). have following code sample program:
#include<iostream> #include<windows.h> #include<winldap.h> using namespace std; int main() { string ldapserverurl = "192.168.10.29"; int ldapserverport = 389; ldap* ldapsession = ldap_init(&ldapserverurl[0], ldapserverport); return 0; }
when try build sample mingw toolchain in eclipse, build fails , line ldap_init()
underlined in red. when hover mouse on error, says "undefined reference _imp__ldap_inita()
." when try cygwin toolchain, yields similar error (with different underscore arrangement).
when try compile via cmd (cd
directory g++ main.cpp
, cygwin in path), error:
/cygdrive/c/users/someuser/appdata/local/temp/cczczwy3.o:main.cpp:(.text+0x68): undefined reference `__imp_ldap_init' /cygdrive/c/users/someuser/appdata/local/temp/cczczwy3.o:main.cpp:(.text+0x68): relocation truncated fit: r_x86_64_pc32 against undefined symbol `__imp_ldap_init' collect2: error: ld returned 1 exit status
i've read __imp_
prefix being related linking (this stuff bit on head, i'm android developer). 1 term came across declspec
. took @ winldap.h
, has following (relevant?) code:
#ifndef winldapapi #define winldapapi declspec_import #endif
but there, have no idea go. how compile?
it turns out did not have windows sdk installed. first thing had download , install it.
then, in eclipse, had make changes project configuration.
first, had add windows sdk paths , symbols include directories (right click project -> properties -> c/c++ general -> paths , symbols -> gnu c++ -> add...). in case, directory had add c:\program files (x86)\windows kits\8.1\lib\winv6.3\um\x64
.
next, had add windows ldap library cygwin c++ linker library configuration (right-click project -> properties -> c/c++ build -> settings -> cygwin c++ linker -> libraries). under "libraries (-l)," add wldap32.lib (case sensitive!).
now builds , runs!
Comments
Post a Comment