Jump to content

C++/DLL GCC TROUBLE!


 Share

Recommended Posts

Ok, and the story goes... Once Apon a Time...

ok, like two days ago, i started attempting to get the main.cpp to compile, and i have spent every waking moment attempting it, banned from two IRC rooms for it being a "Blatently stupid and obvious question..." *shrugs* gues ima moron, that doesnt help, i already knew that... so then i asked a friend of mine who does C++, and he said it sounds like a linking error, i have to tell my compiler to link AutoItX3.lib, but hes a mac c++ programmer, so thats about as much as he could help, so then i make a post, in the wrong location, as i had yet again pointed out my moronic ability :-P, and he said the same thing, linking error... aside from the fact that it said [Linking Error] right in the error report, i wasnt much suprised... ok, so that brings me to about 9pm last night, since then i have downloaded and installed cygwin, and managed to completely compile it using this following line at command prompt:

gcc AutoIt.cpp -o AutoIt.exe -I "/cygdrive/c/AutoIt" -I "/cygdrive/c/Dev-Cpp/include" -L "/cygdrive/c/Dev-Cpp/lib" -mwindows "/cygdrive/c/AutoIt/AutoItX3.lib"

Sounds to good to be true eh? ... well... it was... i go in, double click the AutoIt.exe and i get a little popup box... "cygwin1.dll requied", no sweat, happing hunting... i found it, shot it out of the sky, and placed it in my C:\AutoIt folder, and YAY! IT STARTS! then... does nothing and closes... no errors, no nothing... woot! *sigh* so i go in and find the gcc compiler that came with my Dev-C++ 4.9.9.2 install, i find it, and i run this at the windows command prompt:

C:\AutoIt>gcc AutoIt.cpp -o AutoIt.exe -I "C:\AutoIt" -I "C:\Dev-Cpp\include" -L "C:\Dev-Cpp\lib" -mwindows "C:\AutoIt\AutoItX3.lib"

And i get the following output:

C:\1\2\3\Temp/cceabaaa.o(.text+0xe):AutoIt.cpp: undefined reference to `AU3_Sleep@4'

C:\1\2\3\Temp/cceabaaa.o(.text+0x2d):AutoIt.cpp: undefined reference to `AU3_Run@12'

C:\1\2\3\Temp/cceabaaa.o(.text+0x4c):AutoIt.cpp: undefined reference to `AU3_WinWaitActive@12'

C:\1\2\3\Temp/cceabaaa.o(.text+0x63):AutoIt.cpp: undefined reference to `AU3_Send@8'

collect2: ld returned 1 exit status

Which... was the exact same thing i got out of when i tried to compile it in Dev-C++, though in Dev-C++ when i made a project file out of the code *save as .dev* and added into Project Options > Parameters > Linking the AutoItX3.lib, same error as above, but when i remove the .lib, its FINE! EXCEPT! at one point during the compilation process it sees the AutoItX3 as a directory, and just sends everything down the drain, here is the log file from that compilation:

Compiler: Default compiler

Building Makefile: "C:\AutoIt3\Makefile.win"

Finding dependencies for file: C:\AutoIt3\main.c

Executing make...

make.exe -f "C:\AutoIt3\Makefile.win" all

gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"

gcc.exe main.o -o "AutoIt.exe" -L"C:/Dev-Cpp/lib" -mwindows AutoItX3

gcc.exe: AutoItX3: No such file or directory

make.exe: *** [AutoIt.exe] Error 1

Execution terminated

I have exhausted every thing i know, and everything i could guess at, for the love of god LITTLE RED RIDING HOOD WANTS TO FIND HER WAY HOME! :-P Any Questions?

Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Link to comment
Share on other sites

  • Administrators

Is there a util to convert the VisualC AutoItX3.lib file into a gcc compatible lib file (I know they are supposed to be the same but they don't appear to be. With Borland you have to use implib first, I assume there is something similar for gcc)

Link to comment
Share on other sites

Trying to use the AutoItX3.dll in my own program, though i didnt write the code, im just trying to compile the example program that came in the autoit zip file, its main.cpp

Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Link to comment
Share on other sites

  • 2 weeks later...

2 days and still no fruther then i was... perhaps i didnt get the magical compiler? :-(

<{POST_SNAPBACK}>

X,

I believe the lib is not compatable with gcc. You will need the library source to be compiled with gcc/mingw in order to use it with gcc/mingw. wxWidgets is a classic example. Don't forget the libs under gcc also have a different extention. They use the .a extention instead of .lib.

:) You could download the MS VC++ Toolkit 2003 which contains their free compiler and extract/ install it. Then you could use Code::Blocks to compile the example. No guar. it will work although it should. :evil:

Later.

Link to comment
Share on other sites

  • Administrators

I still think the link I posted above is on the right tracks.

How can an MSVC program call a MinGW DLL, and vice versa?

Assume we have a testdll.h, testdll.c, and testmain.c. In the first case, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should use

gcc -shared -o testdll.dll testdll.c \

    -Wl,--output-def,testdll.def,--out-implib,libtestdll.a

to produce the DLL and DEF files. MSVC cannot use the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool:

lib /machine:i386 /def:testdll.def

Once you have testdll.lib, it is trivial to produce the executable with MSVC:

cl testmain.c testdll.lib

Now for MinGW programs calling an MSVC DLL. We have two methods. One way is to specify the LIB files directly on the command line after the main program. For example, after

cl /LD testdll.c

use

gcc -o testmain testmain.c testdll.lib

The other way is to produce the .a files for GCC. For __cdecl functions (in most cases), it is simple: you only need to apply the reimp tool from Anders Norlander (since his web site is no longer available, you may choose to download here a version enhanced by Jose Fonseca):

reimp testdll.lib

gcc -o testmain testmain.c -L. -ltestdll

However, for __stdcall functions, the above method does not work. For MSVC will prefix an underscore to __stdcall functions while MinGW will not. The right way is to produce the DEF file using the pexports tool included in the mingw-utils package and filter off the first underscore by sed:

pexports testdll.dll | sed "s/^_//" > testdll.def

Then, when using dlltool to produce the import library, add `-U' to the command line:

dlltool -U -d testdll.def -l libtestdll.a

And now, you can proceed in the usual way:

gcc -o testmain testmain.c -L. -ltestdll

Hooray, we got it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...