2012-07-25 82 views
4

我一直在试图用静态库Gtest(gtest_main.a)框架构建我的C项目。我已经包括在有关库文件和相应的路径IDE信息链接部分,但我仍然得到以下错误:在eclipse中链接静态库

 
******** Build of configuration Debug for project CPP_GTEST **** 
**** Internal Builder is used for build    **** 
g++ -LC:/UT_automation_tools/CPP_GTEST/lib -o CPP_GTEST.exe ut_src\ut_asd.o mock_lib\sgn\sgn_asd.o asd\asd.o -lgtest_main 
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgtest_main 
collect2: ld returned 1 exit status 
Build error occurred, build is stopped 
Time consumed: 750 ms.**** 

我已经把链接器命令行patterb,因为它是默认其存在于eclipse ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

我一直在用谷歌搜索来解决这个问题,并且我尝试了各种方法,我通过google搜索时却没能解决问题。

+2

[看到我的帖子] [1]。我今天解决了它。 [1]:http://stackoverflow.com/questions/11636755/eclipse-cdt-how-to-link-with-static-library/11644899#11644899 – 2012-07-25 13:09:28

+0

是的,我按照如在建议该链接通过向工作空间添加静态库并在适当的位置提供静态库路径和名称(不带扩展名.a),但仍会出现相同的错误。任何提示?谢谢 !! – Thiru 2012-07-25 13:39:58

+0

将其放入您的项目中。确保你没有lib作为前缀 – 2012-07-25 13:46:39

回答

2

正如你已经发现,链接器参数-lName导致链接搜索库路径libName.a

为系统的详细信息在LD请参见手册页 - 矿山规定:

-l namespec 
    --library=namespec 
     Add the archive or object file specified by namespec to the list of files to link. This option 
     may be used any number of times. If namespec is of the form :filename, ld will search the 
     library path for a file called filename, otherwise it will search the library path for a file 
     called libnamespec.a.