0

According to this question,

Dynamic linking is done at run time, by the operating system.

Until now, using g++ with eclipse CDT, I statically linked odbc32.lib I got from windows SDK to get some ODBC functions to my program. But I deleted the file by accident and was surprised to find my program still running and connecting to the database. Since the file no longer existed the the path I specified to the -L option, I thought it must still exist somewhere in one of the subfolders of the path. But then I deleted the library path to see what happens but my program still works! I began searching for odbc32.lib and I really can't find it. However, I do found a odbc32.dll file located in C:\Windows\System32 and I thought it might be dynamically linked to my program.

  • If I'm right, How does the compiler find odbc32.dll when I never specified C:\Windows\System32 as my library path?
  • To test my theory, I began grabbing many .dll files in the system32 folder and linked them using -llibrary. I've managed to link some of the files I got because my program run successfully, but some files can't be found by the linker, why is that?

Am I right? Is this an example of dynamic linking?

Note: I also removed C:\Windows\System32 from my path but it's still, for some reason, working.

Community
  • 1
  • 1
lightning_missile
  • 2,821
  • 5
  • 30
  • 58
  • Have you checked your `%PATH%` to see if the it includes `C:\Windows\System32`? Also, on windows, the `.lib` file is needed for linking at compilation but after that it needs the `.dll` at runtime unless the library was specifically compiled to be static. – rhodysurf Mar 10 '15 at 18:39
  • @rhodysurf yes %PATH% includes C:\Windows\System32. But I deleted it just now, but it's still working! You said "on windows, the .lib file is needed for linking at compilation" - so you mean it should not compile without it? Is there a way to find where g++ is getting the library? – lightning_missile Mar 10 '15 at 18:52
  • yes, unless you are linking a library to another library – rhodysurf Mar 10 '15 at 18:55
  • @rhodysurf by yes you mean I can find out where the compiler is getting the library it's linking with? – lightning_missile Mar 10 '15 at 18:57
  • No I mean it shouldn't compile without the lib. You should be able to see what it links to when it compiles using `g++ -v`. I'm not sure about others ways to do it on Windows though – rhodysurf Mar 10 '15 at 19:00
  • @rhodysurf damn! there's a libodbc32.a file under C:\cygwin64\lib\w32api! I might be using this library all along! I transfered it to another folder and my compiler thankfully gave an error. Does this mean I do not need to specify a file path if it's under cygwin? – lightning_missile Mar 10 '15 at 19:28
  • right... because you are using cygwin that changes everything...... Linking is now done as it is on linux (or unix or whatever) and one library is needed, in your case this is static library so it links upon compilation and doesnt need it again. I recommend googling linux library linking – rhodysurf Mar 10 '15 at 19:33
  • @rhodysurf right you effectively answered my question with your last comment. If you don't mind would you post it as an answer? Thanks a lot! – lightning_missile Mar 10 '15 at 19:37

1 Answers1

0

From your comments, you stated you are using g++ with cygwin. Basically this means that linking is now done as it is on linux (or unix or whatever) and one library is needed. In your case this is static library so it links upon compilation and doesn't need it again.

rhodysurf
  • 357
  • 1
  • 4
  • 12