Including source files from another C++ project in Eclipse CDT

前端 未结 4 1296
离开以前
离开以前 2021-02-04 06:57

I have a C++ project in Eclipse CDT which uses some functions from OpevCV and it compiles into an executable and works fine. Now I want to have a new C++ project which uses some

相关标签:
4条回答
  • 2021-02-04 07:20

    Go to Project->Properties->C/C++ general->Paths and Symbols. Select the 'Source Location' tab and click the 'Link Folder...' button. You should be able to select the directory containing the project you want to reference. All the source files for that project will be included in your current project. Works for me anyway.

    0 讨论(0)
  • 2021-02-04 07:27

    I personally like CMake to specify my build options. CMake projects can also be imported into Eclipse CDT. CMake allows you to generate make file projects on linux, but also VS projects on windows. The OpenCV website also gives an example on how to use it with CMake.

    0 讨论(0)
  • 2021-02-04 07:34

    As a new user I could not comment on Itay Gal's answer, so this is a really klunky way to add to that answer. My additions may be stating the obvious, but it was not all that obvious to me.

    From Itay Gal You have to define 2 things:

    from the referring project

    1. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Source Location tab and click the Link Folder..., Then select the folder you want to include.

    To "select the folder you want to include", I used Link Folder->Advanced, clicked the "Link to Folder in the file system" check-box and browsed to my folder's location, which is in my workspace location. The "folder name" is the sub directory of my referring project in which my referenced files will appear and was filled in automatically when I selected my referenced folder. You can edit the folder name, but you cannot give it a path so as to make it a sub-directory.

    2. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Includes tab. Make sure you select the correct language on the left menu (for example: GNU C++) and click Add..., Then select the folder you want to include.

    Expanding upon "select the folder you want to include", from the "includes" tab, I clicked Add->Workspace, selected the referenced project and browsed to the referenced folder and clicked OK

    I did not make my external project as a library, just a few files kept in another git repository which do not even build by themselves. I wanted them separate because the code is used in common by several other projects.

    To make sure you did everything OK, go to : Project->Properties->C/C++ Build->Settings. Select the GCC C++ Linker and make sure that the All options contains "-L/your_folder_name". Repeat this for GCC C++ Compiler also.

    I found my linked project under Project->Properties->C/C++Build->Settings->Cross ARM C++ Compiler in the "all options" window, but not in the ->Cross ARM C++ Linker tab "all options" window. My code seems to build properly and properly launch a debug window anyway.

    Many thanks to Itay gal for the answer.

    So it worked great for my first project, as reported above. Then I tried to do the same thing with two other projects which needed to use the referenced code. After spending a long bit of time, I concluded that the project includes were different in the "Sources" directory than they were in the overall project. If you select the project and apply step 2 you get a different result than if you select the "Source" directory and apply step 2. This might be something I managed to inadvertently turn on in floundering around learning about eclipse, but if it is I see nowhere to turn it off.

    0 讨论(0)
  • 2021-02-04 07:39

    I was looking for an answer too but the previous answers did not solve the problem. (Nick's answer was helpful). You have to define 2 things:

    1. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Source Location tab and click the Link Folder..., Then select the folder you want to include.
    2. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Includes tab. Make sure you select the correct language on the left menu (for example: GNU C++) and click Add..., Then select the folder you want to include.

    Note: I'm not sure it's necessary but when I created the external project I selected the "Shared Library" option in the new project wizard.

    To make sure you did everything OK, go to : Project->Properties->C/C++ Build->Settings. Select the GCC C++ Linker and make sure that the All options contains "-L/your_folder_name". Repeat this for GCC C++ Compiler also.

    0 讨论(0)
提交回复
热议问题