Help with Windows/C++/Borland/popt (yes, all at the same time)

Discussion in 'OT Technology' started by Penguin Man, Jun 6, 2003.

  1. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Hey, so I'm writing my final project for my programming class, it's a port scanner. The port scanner part works perfectly (uses WinSock, pretty simple really). So, now I'm looking at adding some commandline arguments to it. At home (on my Linux box), I've been playing with popt to handle arguments, and I quite like it, got it working quite well. So, I download popt for windows at school (from http://gnuwin32.sourceforge.net) and put popt.dll and popt.h in the same dir as the program, then #include "popt.h". All goes well in compilation. It gets to the linking stage and gives me link errors saying it can't find the popt functions, indicating to me that there's some problem using the dll or something. Also tried putting the dll in c:\windows, it didn't help.

    So everyone knows, I'm using:
    Windows 98 (don't tell me to upgrade, were it up to me the lab would be Linux, but our tech is pretty dumb)
    Borland C++ compiler (not sure what version)

    Any help?
     
  2. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
  3. Scoob_13

    Scoob_13 Anything is possible, but the odds are astronomica

    Joined:
    Oct 5, 2001
    Messages:
    73,798
    Likes Received:
    38
    Location:
    Fort Worth. Hooray cowgirls.
    It's because you're from Canada :o

    Did you check the instructions for Popt for Windows?
     
  4. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yes, they're fucking useless.

    Anyway, I played with parsint it (albeit not quite as nicely) myself tonight and it works, so I think I'll just do that.

    BTW, I HATE programming on Windows.
     
  5. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    check the make file. i was having a problem with programming a QT application in windows to that extent and found out that the .h file was not listed in the dependency list in my make file
     
  6. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    There is no makefile, this is Windows.
     
  7. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    oh there is still a makefile, you just dont have to specifically deal with it like you do in with g++. windows uses nmake to handle make files whereas linux machines use make. check for yourself if you dont believe me
     
  8. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yes, there is a makefile, but that doesn't help me since this school computer doesn't have make or any other gnu-like utilities and I can't install them (well, I can but the'll be gone next time I log on) and really don't feel like doing anything.

    Besides which, I'm sure it's not compiler arguments that are the problem, I tried it with bcc on the commandline as well as in Visual C++ (which does all the linking stuff automatically).
     
  9. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    Do you have an implicit link import library? If you're not explicitly linking the DLL's routines using LoadLibrary(), then you need an import lib to link a DLL. I haven't used Borland in years, but there used to be a utility for borland called IMPLIB that would create an import library for a DLL.
     
  10. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    I have no idea what you mean by implicit link import library. Please explain.

    Anyway, I ended up doing it manually and it works well enough. Still interested to learn more about this though (in case, god forbit, I ever have to use DLL's again).
     
  11. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    There are two methods of linking to a DLL: explicit and implicit.

    The explicit method requires you to call LoadLibrary() to load the DLL, then call GetProcAddress() to retrieve function pointers for the routines you want to call. This method is useful if you don't know the name of the DLL or routines at link time. Applications that are extensible via "plug-ins" can be implemented this way.

    The implicit method allows you to declare function prototypes as if you were linking to a static library (i.e. your popt.h), and you don't have to worry about setting up the DLL with LoadLibrary() and GetProcAddress(). But, the linker requires a special static library. This import library contains the stub functions used to call the DLL routines and also contains code which automatically performs the LoadLibrary() and GetProcAddress() tasks when your app is run.

    In Visual C++, when you create a DLL, an import lib is generated automatically. You'd get popt.dll along with popt.lib which you'd then link into whatever project you wanted to use the DLL with. Borland probably has a similar deal. If not, you could use IMPLIB to create an import library.
     
  12. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Thanks, I might try that out tomorrow if I have some time. And come to think of it, I believe I can download the .lib file from the popt website.
     
  13. R-Type

    R-Type The Bydo Empire must die!

    Joined:
    Aug 2, 2002
    Messages:
    1,049
    Likes Received:
    0
    Location:
    CT
    You could try using the argc/argv parameters for your main() function. argc contains the integer value of the number of parameters passed to your program and argv is a null pointer to an array of the command line arguements. It doesn't require any external libs and is fairly cross platform.

    From your post it would seem the linker can't find popt.lib. Try either copying that lib into your 'lib' dir in your borland installation, or adding the path to popt.lib in your project.
     
    Last edited: Jun 14, 2003
  14. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Duh. All popt does is parse up argv for you so it's super easy to use. And what I ended up doing was parsing it up manually with a for loop and a case statement. Works well enough.
     
  15. R-Type

    R-Type The Bydo Empire must die!

    Joined:
    Aug 2, 2002
    Messages:
    1,049
    Likes Received:
    0
    Location:
    CT
    hehe ok..I've never used popt so I don't know anything about it. I always just parsed argv manually.
     

Share This Page