Is there a reason to not use target_link_libraries here? For the purposes of your example there's no reason to be using CMAKE_EXE_LINKER_FLAGS. What are you actually trying to accomplish? Because there is almost certainly a better way to achieve your desired result than via CMAKE_EXE_LINKER_FLAGS.
- Chuck On Fri, May 20, 2016 at 4:28 AM, Chaos Zhang <zcsd2...@gmail.com> wrote: > Hi, all, > > I try to use some gcc link option and libs(except libs link by > target_link_libraries(...)), i researched and try to use > 'CMAKE_EXE_LINKER_FLAGS' in a simple project, as below: > in dir, there are 5 files: > > -hello.h > -hello.c > -main.c > -hello.o > -libhello.a > > hello.o was compiled by hello.c(gcc -c hello.c) and libhello.a contained > hello.o. And other 3 files content: > 1.In hello.h: > > void hello(); > > 2.In hello.c: > > #include<stdio.h> > void hello() > { > printf("hello\n"); > } > > 3.In main.c: > > #include "hello.h" > void main() > { > hello(); > } > > When i used gcc -o main main.c libhello.a, the exe file: main generated, > and > it work well. > Then i write a CMakeLists.txt, the content as below: > > set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L . -lhello") > add_executable(main main.c) > > When i cmake&make this project, an error occurred: main.c:undefined > reference to 'hello'. > > Since i wil add a complicated link option and would not conflict with libs > link by target_link_libraries(...), i should figure out how to use > 'CMAKE_EXE_LINKER_FLAGS' or other ways, could you please give me some > advices? :-) > > Thanks, > Chao > > > > -- > View this message in context: > http://cmake.3232098.n2.nabble.com/How-to-use-CMAKE-EXE-LINKER-FLAGS-correctly-tp7593495.html > Sent from the CMake mailing list archive at Nabble.com. > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > http://public.kitware.com/mailman/listinfo/cmake >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake