GCC/LD cannot find link library

女生的网名这么多〃 提交于 2020-01-02 03:34:51

问题


OS: Windows 7 Enterprise x64 IDE: Eclipse Juno/CDT Compiler: MinGW 4.6.2 (C:\MinGW)

Like user697111, I cannot get ld.exe to find an external library.

Simple programs compile and link fine, but when I try to add SQL funcionality with the supplied library, I get this error message in Eclipse: "c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lC:\MinGW\lib\libodbc32.a".

I specified C:\MinGW\lib as the Project Library Path. I specified C:\MinGW\lib\libodbc32.a as the one-and-only Project Library (this made the unresolved-reference errors go away in the IDE).

I switched to the CLI and pasted the compile command. For the library name, I've tried: odbc32, odbc32.a, libodbc32, libcodbc32.a I also tried: odbccp32, odbccp32.a, libodbccp32, libodbccp32.a I've used forward slashes, backslashes, double-backslashes, quotes around the path, quotes around the entire -l parameter (which is what Eclipse does to the -L parameter).

I copied the libraries into the directory containing the compiled code to eliminate the need to specify the path. I copied them into the directory containing ld.exe. I updated the Windows path to include the directory and restarted Eclipse and the CLI.

If I remove the -l parameter entirely, I get all kinds of unresolved-reference errors. It seems ld.exe is finding the library but is bent on hiding the real problem.

What is the secret to linking to the built-in SQL libraries?


回答1:


Got it at last!

When using the CLI, don't include the path in the -l parameter, drop the ".a" suffix and the "lib" prefix: -lodbc32 The path is supplied by the -L parameter.

To make it work in Eclipse, edit the Library entry (Project Properties/Paths and Symbols/Libraries tab) after adding it. Remove the path, "lib", and ".a". (Eclipse will warn about the dangers of using relative paths.) Remember this step whenever you add an external library.

It now works fine in both Eclipse and the CLI.



来源:https://stackoverflow.com/questions/17031290/gcc-ld-cannot-find-link-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!