Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Eclipse IDE GCC linker options ?

Eclipse IDE GCC linker options ?

Scheduled Pinned Locked Moved C / C++ / MFC
questionvisual-studiohelp
16 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vaclav_

    Could I post a question about Eclipse ? Have a problem linking to library ( GCC options -L -l) and for a week I got no response elsewhere. Thanks for checking. Cheers ' Vaclav

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Vaclav_Sal wrote:

    Could I post a question about Eclipse ?

    Yes, you may.

    Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.

    1 Reply Last reply
    0
    • V Vaclav_

      Could I post a question about Eclipse ? Have a problem linking to library ( GCC options -L -l) and for a week I got no response elsewhere. Thanks for checking. Cheers ' Vaclav

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #3

      Sure but there isn't much to those two they are just followed by a folder path string for the library directory or the include directory. For header files GCC uses 4 default directories in a set order, the name of those directories is set when the version of GCC.EXE was created. So I can't tell you what they are because it depends on versions, CPU etc. However you can get them back out to screen with a command GCC -v I don't do a lot with libraries and from what I know there are 2 default directories in a set order again set at compile time of the linker executable ld.exe and again it has a command to display them ld -v Your commands above change the user directories and you can check what is happening by inserting your command line and putting -v at end and you can see what it changes.

      In vino veritas

      V 1 Reply Last reply
      0
      • L leon de boer

        Sure but there isn't much to those two they are just followed by a folder path string for the library directory or the include directory. For header files GCC uses 4 default directories in a set order, the name of those directories is set when the version of GCC.EXE was created. So I can't tell you what they are because it depends on versions, CPU etc. However you can get them back out to screen with a command GCC -v I don't do a lot with libraries and from what I know there are 2 default directories in a set order again set at compile time of the linker executable ld.exe and again it has a command to display them ld -v Your commands above change the user directories and you can check what is happening by inserting your command line and putting -v at end and you can see what it changes.

        In vino veritas

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #4

        Thanks Leon, this is my first usage of Eclipse and I am in "GUI" stage so far. The problem is little too much for me. First I used install.sh script for OpenCV and added "library search path" (-L) /usr/local/lib. Than I am suppose to choose the actual library to use via (-l) from pull down box - but there is no pull down , only text box. After "updating " Eclipse to newest I noticed that when I type in search path /usr/local/lib it ends up as "/usr/local/lib" , but still no pull down box with the libraries. I must be missing some other option. ( I do wish I was better using command line, but I am not ready for it.) So I added cv2.so under library add (-l) . Now everything compiles , but linker stops because it cannot find the "cv2.so" - but I can see it in correct directory. I still think my (-l) syntax is wrong. I also tryied to link to OpenCV .../build/lib with same results . This "build/lib" was a product of CMake I found with OpenCV. I think my biggest issue is - I do not understand how does "shared" library works in Elipse and which library search path is correct.

        L J L 3 Replies Last reply
        0
        • V Vaclav_

          Thanks Leon, this is my first usage of Eclipse and I am in "GUI" stage so far. The problem is little too much for me. First I used install.sh script for OpenCV and added "library search path" (-L) /usr/local/lib. Than I am suppose to choose the actual library to use via (-l) from pull down box - but there is no pull down , only text box. After "updating " Eclipse to newest I noticed that when I type in search path /usr/local/lib it ends up as "/usr/local/lib" , but still no pull down box with the libraries. I must be missing some other option. ( I do wish I was better using command line, but I am not ready for it.) So I added cv2.so under library add (-l) . Now everything compiles , but linker stops because it cannot find the "cv2.so" - but I can see it in correct directory. I still think my (-l) syntax is wrong. I also tryied to link to OpenCV .../build/lib with same results . This "build/lib" was a product of CMake I found with OpenCV. I think my biggest issue is - I do not understand how does "shared" library works in Elipse and which library search path is correct.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          Have you checked at CDT Documentation[^]? The command line options for GCC will all be listed on the GCC website, but generally for linking you need the directories listed via -L (capital L), and the names of the libraries vie -l (small l). It is sometime since I have built an application on Unix/Linux so some features may have changed. It would probably help if you showed your complete GCC command line (between <pre> tags for clarity.) and the exact error message(s) that you receive.

          1 Reply Last reply
          0
          • V Vaclav_

            Thanks Leon, this is my first usage of Eclipse and I am in "GUI" stage so far. The problem is little too much for me. First I used install.sh script for OpenCV and added "library search path" (-L) /usr/local/lib. Than I am suppose to choose the actual library to use via (-l) from pull down box - but there is no pull down , only text box. After "updating " Eclipse to newest I noticed that when I type in search path /usr/local/lib it ends up as "/usr/local/lib" , but still no pull down box with the libraries. I must be missing some other option. ( I do wish I was better using command line, but I am not ready for it.) So I added cv2.so under library add (-l) . Now everything compiles , but linker stops because it cannot find the "cv2.so" - but I can see it in correct directory. I still think my (-l) syntax is wrong. I also tryied to link to OpenCV .../build/lib with same results . This "build/lib" was a product of CMake I found with OpenCV. I think my biggest issue is - I do not understand how does "shared" library works in Elipse and which library search path is correct.

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #6

            When passing library file names using the -l option strip of the lib prefix and the extension. If for example the file name is libcv2.so, pass -lcv2 as option. See Link Options - Using the GNU Compiler Collection (GCC)[^]. If the library file does not match this style (lib prefix, .a or .so extension, or you want to link dynamically to a .so file but there is also a matching .a file), you can pass the full name with path as argument like for object files (gcc recognises if the file is an object file or a libray). I can't help much regarding Eclipse. But a quick search shows that there are two different sections where you can configure libraries:

            1. The general library settings (C/C++ Properties - Folder - General - Paths and Symbols)
            2. The project and tool specific settings (C/C++ Properties - Project - Build - Settings - Tool Settings - Linker)

            The first should be used for system wide general library paths while the second is for project specific settings. To add an object or library with full path and name, enter it at Miscellaneous - Other objects.

            1 Reply Last reply
            0
            • V Vaclav_

              Thanks Leon, this is my first usage of Eclipse and I am in "GUI" stage so far. The problem is little too much for me. First I used install.sh script for OpenCV and added "library search path" (-L) /usr/local/lib. Than I am suppose to choose the actual library to use via (-l) from pull down box - but there is no pull down , only text box. After "updating " Eclipse to newest I noticed that when I type in search path /usr/local/lib it ends up as "/usr/local/lib" , but still no pull down box with the libraries. I must be missing some other option. ( I do wish I was better using command line, but I am not ready for it.) So I added cv2.so under library add (-l) . Now everything compiles , but linker stops because it cannot find the "cv2.so" - but I can see it in correct directory. I still think my (-l) syntax is wrong. I also tryied to link to OpenCV .../build/lib with same results . This "build/lib" was a product of CMake I found with OpenCV. I think my biggest issue is - I do not understand how does "shared" library works in Elipse and which library search path is correct.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #7

              Jochen gave a full detail but I am going reduce his answer down to make it simpler gcc -l sets a library file name to link (we are assuming the file is in the library directory chains). gcc -L Sets the directory for library files. So the little l is a library file name (so it will be -l cv2 in your case), it's a simple name no folder, no extension. cv2.so is a shared object file so if the linker can't find it and it's there ... then your big L setting is wrong. So your big L should be -L /usr/local/lib Look at the command Eclipse fires out onto the command line and look for those two.

              In vino veritas

              V 1 Reply Last reply
              0
              • L leon de boer

                Jochen gave a full detail but I am going reduce his answer down to make it simpler gcc -l sets a library file name to link (we are assuming the file is in the library directory chains). gcc -L Sets the directory for library files. So the little l is a library file name (so it will be -l cv2 in your case), it's a simple name no folder, no extension. cv2.so is a shared object file so if the linker can't find it and it's there ... then your big L setting is wrong. So your big L should be -L /usr/local/lib Look at the command Eclipse fires out onto the command line and look for those two.

                In vino veritas

                V Offline
                V Offline
                Vaclav_
                wrote on last edited by
                #8

                Thanks to all, I really appreciate your help. I did some more messing around and managed to input correct -L using / copying stuff affecting ALL projects. It sort off worked. Than I did -l and typed cv2.so and the linker could not find it. I'll try just cv2 without the so extension next. AS I said , there is an GUI option to select "shared" files so as soon as I can get the linker to work I'll play with that. I just rebuild another "buidl" using CMake again and will see what I messed up this time. I'll cannot post the linker output until I have it back working after this new Make, sorry.

                V 1 Reply Last reply
                0
                • V Vaclav_

                  Thanks to all, I really appreciate your help. I did some more messing around and managed to input correct -L using / copying stuff affecting ALL projects. It sort off worked. Than I did -l and typed cv2.so and the linker could not find it. I'll try just cv2 without the so extension next. AS I said , there is an GUI option to select "shared" files so as soon as I can get the linker to work I'll play with that. I just rebuild another "buidl" using CMake again and will see what I messed up this time. I'll cannot post the linker output until I have it back working after this new Make, sorry.

                  V Offline
                  V Offline
                  Vaclav_
                  wrote on last edited by
                  #9

                  Here is what I am getting, I need to find out what /ld is , maybe that will give me a clue. And here is a terrible though - how do I verify that OpenCV will work on Unbutu - 32 bits and Eclipse - also 32 bits? I can run "hello world", but cannot get the linker to work with OpenCV. **** Build of configuration Debug for project TEST_1 **** **** Internal Builder is used for build **** g++ -L/usr/local/lib -shared -L/media/jim/OpenCL/OpenCV/build/lib -shared -olibTEST_1 src/TEST_1.o -l/cv2 -l/cv2.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio -llibopencv_videoio /usr/bin/ld: cannot find -l/cv2 /usr/bin/ld: cannot find -l/cv2.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio /usr/bin/ld: cannot find -llibopencv_videoio collect2: error: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 186 ms.

                  L L J 3 Replies Last reply
                  0
                  • V Vaclav_

                    Here is what I am getting, I need to find out what /ld is , maybe that will give me a clue. And here is a terrible though - how do I verify that OpenCV will work on Unbutu - 32 bits and Eclipse - also 32 bits? I can run "hello world", but cannot get the linker to work with OpenCV. **** Build of configuration Debug for project TEST_1 **** **** Internal Builder is used for build **** g++ -L/usr/local/lib -shared -L/media/jim/OpenCL/OpenCV/build/lib -shared -olibTEST_1 src/TEST_1.o -l/cv2 -l/cv2.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio -llibopencv_videoio /usr/bin/ld: cannot find -l/cv2 /usr/bin/ld: cannot find -l/cv2.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio /usr/bin/ld: cannot find -llibopencv_videoio collect2: error: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 186 ms.

                    L Offline
                    L Offline
                    leon de boer
                    wrote on last edited by
                    #10

                    You only need one of these for cv2

                    -l/cv2 -l/cv2.so

                    but as neither is working, try fully qualifying it as a single entry which means use a colon

                    -l:cv2.so

                    The reason I think you are having to do that is you have not set GCC command with the -shared cv2.so if you look you have -shared and nothing after it You have can set the -L directory I don't think the -l command can have directory entries :-)

                    -L/my/long/directory -lfoo -L/my/other/even/longer/directory -lfoo1

                    That I believe is how you do library foo & foo1 from different long directories Edit: I also see above you got the make file sort of working so you must be able to see the actual command lines to the linker.

                    In vino veritas

                    V 1 Reply Last reply
                    0
                    • V Vaclav_

                      Here is what I am getting, I need to find out what /ld is , maybe that will give me a clue. And here is a terrible though - how do I verify that OpenCV will work on Unbutu - 32 bits and Eclipse - also 32 bits? I can run "hello world", but cannot get the linker to work with OpenCV. **** Build of configuration Debug for project TEST_1 **** **** Internal Builder is used for build **** g++ -L/usr/local/lib -shared -L/media/jim/OpenCL/OpenCV/build/lib -shared -olibTEST_1 src/TEST_1.o -l/cv2 -l/cv2.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio -llibopencv_videoio /usr/bin/ld: cannot find -l/cv2 /usr/bin/ld: cannot find -l/cv2.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio /usr/bin/ld: cannot find -llibopencv_videoio collect2: error: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 186 ms.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      ld is the linker which collects all the object modules and libraries, and combines them into a new library, or an executable program. The library options to the linker are as follows: -L followed by a directory path, adds that directory to the list of locations to be searched for any additional libraries. -l add the undecorated library name to the list of libraries required by the object code. Note that libraries are commonly held in files which are named liblibraryname**.suffix**, where suffix is .a or .so. However the name specified on the option line should just be libraryname, i.e. no preceing lib and no suffix. And no directory paths. So the options you should be using for /media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a should be something like:

                      -L/media/jim/OpenCL/OpenCV/build/lib
                      -lopencv_flann_pch_dephelp

                      And it would really make your questions easier to read if you would use <pre> tags as requested many times.

                      1 Reply Last reply
                      0
                      • L leon de boer

                        You only need one of these for cv2

                        -l/cv2 -l/cv2.so

                        but as neither is working, try fully qualifying it as a single entry which means use a colon

                        -l:cv2.so

                        The reason I think you are having to do that is you have not set GCC command with the -shared cv2.so if you look you have -shared and nothing after it You have can set the -L directory I don't think the -l command can have directory entries :-)

                        -L/my/long/directory -lfoo -L/my/other/even/longer/directory -lfoo1

                        That I believe is how you do library foo & foo1 from different long directories Edit: I also see above you got the make file sort of working so you must be able to see the actual command lines to the linker.

                        In vino veritas

                        V Offline
                        V Offline
                        Vaclav_
                        wrote on last edited by
                        #12

                        Good news, it linked AFTER I changed the -l to -l:cv2.so I'll check the GCC linker -l option and try to figure it out. It seems I should not have to add the .so extension to the file name. But it would not work without it, probably related to -shared option too. As far as the -shared - it is a common option and I need to find out how it works too. I beginning to believe the Elipse Settings GUI is not telling the whole story as far as how to use it. There is "Common" window dialog of all the options currently set , but it cannot be edited !

                        L 1 Reply Last reply
                        0
                        • V Vaclav_

                          Here is what I am getting, I need to find out what /ld is , maybe that will give me a clue. And here is a terrible though - how do I verify that OpenCV will work on Unbutu - 32 bits and Eclipse - also 32 bits? I can run "hello world", but cannot get the linker to work with OpenCV. **** Build of configuration Debug for project TEST_1 **** **** Internal Builder is used for build **** g++ -L/usr/local/lib -shared -L/media/jim/OpenCL/OpenCV/build/lib -shared -olibTEST_1 src/TEST_1.o -l/cv2 -l/cv2.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio -llibopencv_videoio /usr/bin/ld: cannot find -l/cv2 /usr/bin/ld: cannot find -l/cv2.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_flann_pch_dephelp.a /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio.so /usr/bin/ld: cannot find -l/media/jim/OpenCL/OpenCV/build/lib/libopencv_videoio /usr/bin/ld: cannot find -llibopencv_videoio collect2: error: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 186 ms.

                          J Offline
                          J Offline
                          Jochen Arndt
                          wrote on last edited by
                          #13

                          To nail it down again: The -l option requires a stripped library name without path, lib prefix, and extension! When specifying all library pathes with the -L option, it must be just:

                          -lcv2
                          -lopencv_flann_pch_dephelp
                          -lopencv_videoio

                          The linker (ld) will then search all directories specified with the -L option for matching files by building the full name from the path actually searched, appending the lib prefix, appending the name passed to the -l option, and appending the extension .a. If that fails for a path, it tries again with the extension .so.

                          V 1 Reply Last reply
                          0
                          • J Jochen Arndt

                            To nail it down again: The -l option requires a stripped library name without path, lib prefix, and extension! When specifying all library pathes with the -L option, it must be just:

                            -lcv2
                            -lopencv_flann_pch_dephelp
                            -lopencv_videoio

                            The linker (ld) will then search all directories specified with the -L option for matching files by building the full name from the path actually searched, appending the lib prefix, appending the name passed to the -l option, and appending the extension .a. If that fails for a path, it tries again with the extension .so.

                            V Offline
                            V Offline
                            Vaclav_
                            wrote on last edited by
                            #14

                            Yes, that is how is SHOULD work per GCC linker.

                            L 1 Reply Last reply
                            0
                            • V Vaclav_

                              Good news, it linked AFTER I changed the -l to -l:cv2.so I'll check the GCC linker -l option and try to figure it out. It seems I should not have to add the .so extension to the file name. But it would not work without it, probably related to -shared option too. As far as the -shared - it is a common option and I need to find out how it works too. I beginning to believe the Elipse Settings GUI is not telling the whole story as far as how to use it. There is "Common" window dialog of all the options currently set , but it cannot be edited !

                              L Offline
                              L Offline
                              leon de boer
                              wrote on last edited by
                              #15

                              Yeah sorry I can't help with Eclipse I just put GCC on my external tools menu on Visual Studio 2015 :-) I am too slack to learn another IDE.

                              In vino veritas

                              1 Reply Last reply
                              0
                              • V Vaclav_

                                Yes, that is how is SHOULD work per GCC linker.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #16

                                And that is how it does work. You just need to ensure that your options and parameters are specified correctly.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups