[mingw - Windows API] I can't link Windows libraries with C++ code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[mingw - Windows API] I can't link Windows libraries with C++ code

SourceForge.net

Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=3212483
By: aedgsilva

I can't make the following code work:

#include <iostream>
#include <wininet.h>
using namespace std;

int main (int argc, char *argv[])
{
  cout << "Starting internet environment...\n";
  HINTERNET conn = InternetOpenA ("eComex Patch Maker", INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, 0);

  cout << "Connecting to ftp.ecomex.com.br server...\n";
  HINTERNET ftp = InternetConnectA (conn, "ftp.ecomex.com.br",
INTERNET_DEFAULT_FTP_PORT, "name", "passwd", INTERNET_SERVICE_FTP, 0, 0);

  cout << "Changing directory to httpdocs/patches...\n";
  FtpSetCurrentDirectoryA (ftp, "httpdocs/patches");

  cout << "Sending test.txt file...\n";
  FtpPutFileA (ftp, "test.txt", "test.txt", FTP_TRANSFER_TYPE_ASCII, 0);

  cout << "Closing connection and environment...\n";
  InternetCloseHandle (ftp);
  InternetCloseHandle (conn);

  return 0;
}

C:\> g++ -c -o ftp.o ftp.cpp

C:\> g++ -o ftp.exe -lwininet ftp.o
Reading specs from C:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared
--enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x
--enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
 C:/Usr/MinGW/bin/../libexec/gcc/mingw32/3.4.2/collect2.exe -Bdynamic -o ftp.exe
C:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o
C:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/crtbegin.o
-LC:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2 -LC:/Usr/MinGW/bin/../lib/gcc
-LC:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib
-LC:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../.. -lwininet ftp.o -lstdc++
-lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32
-lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
C:/Usr/MinGW/bin/../lib/gcc/mingw32/3.4.2/crtend.o

ftp.o(.text+0x166):ftp.cpp: undefined reference to `InternetOpenA@20'
ftp.o(.text+0x1c3):ftp.cpp: undefined reference to `InternetConnectA@32'
ftp.o(.text+0x1f0):ftp.cpp: undefined reference to `FtpSetCurrentDirectoryA@8'
ftp.o(.text+0x232):ftp.cpp: undefined reference to `FtpPutFileA@20'
ftp.o(.text+0x254):ftp.cpp: undefined reference to `InternetCloseHandle@4'
ftp.o(.text+0x262):ftp.cpp: undefined reference to `InternetCloseHandle@4'
collect2: ld returned 1 exit status

I tryied every option I knew (--enable-stdcall-fixup etc.) but the result is
the same...

Can some one guive me an advice?

Thanks in advance!

--
Andre

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=286641


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users