设置跨平台 C++带有跨平台库的 Eclipse 项目

发布于 2024-09-24 21:29:34 字数 577 浏览 8 评论 0原文

我正在与其他 8 个人一起开发一个跨平台 C++ 项目,该项目使用以下库:

  • OpenCV 库
  • Boost C++ 库

该项目旨在跨平台,因此所有用户都同意不使用特定于平台的代码,并且,让事情尽可能简单,所有用户都将使用 Eclipse 作为他们的 IDE。但是,有些将使用适用于 Windows 的 Eclipse,而另一些将使用适用于 Linux 的 Eclipse。

由于项目将托管在 SVN 上,我们希望避免与共享的不同配置文件(如 make 文件、eclipse 项目文件等)发生冲突。我们还希望通过 SVN 共享尽可能多的配置文件,以使配置尽可能简单。

假设所有用户都已正确配置系统变量并安装了所需的构建工具(例如 make、cmake 等),并且已正确配置其 Eclipse 设置(但不是特定于项目的设置)。

如何一次性配置项目以及在存储库上共享哪些配置文件,以便 Windows 和 Linux 用户都可以编译它,而无需修改从 SVN 存储库检索的配置文件?

(我并不是在寻找专门适用于我提到的这两个库的完整解决方案,因此我希望有一个通用的逐步说明,这将使我能够轻松添加另一个库。)

I am working on a cross-platform C++ project with 8 other people which uses the following libraries:

  • OpenCV Library
  • Boost C++ Library

The project is inteded to be cross-platform so all users have agreed not to use platform-specific code, and, to keep things as simple as possible, all users will be using Eclipse as their IDE. However, some will be using Eclipse for Windows while other will be using Eclipse for Linux.

Since the project will be hosted on SVN, we would like to avoid conflicts with different configuration files (like make files, eclipse project files etc..) which are shared. We would also like to share as much of the configuration files as possible through SVN, to keep the configuration as simple as possible.

Let's assume that all users have properly configured system variables and installed the required build tools (such as make, cmake etc.), and have configured their Eclipse settings configured properly (but not the project-specific settings).

How to configure the project once and what of the configuration files to share on the repository, so that both Windows and Linux users can compile it without modifying configuration files retrieved from the SVN repository?

(I am not looking for the complete solution which would specifically work for those 2 libraries I mentioned, so I would appreciate a general how-to step-by-step explanations which would enable me to easily add another library.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你再特殊 2024-10-01 21:29:34

一般讨论:

您需要安装 Cygwin 或类似的东西,以使 GNU Autotools 工具链可用于 Windows 上的 Eclipse:
如何处理 Eclipse CDT+Cygwin?

一旦你的工具链 Eclipse 有了CDT 和 SVN 连接器已在您的开发计算机上准备就绪,请执行以下步骤。

  1. 打开Eclipse并切换到CDT:点击Window->Open Perspective->Other...,选择C/C++
  2. 选择:Eclipse->File->New->C++ Project
  3. 项目名称:viewer
  4. 选择:项目类型->GNU Autotools->Hello World C++ Autotools 项目
  5. 单击:下一步
  6. 单击:完成
  7. 在项目资源管理器中右键单击:查看器->重新配置项目
  8. 单击:控制台->显示选定的控制台子菜单-># CDT Global Build Console 。如果“autoreconf -i”输出是名义上的,请继续执行步骤 9。如果控制台报告: sh: autoreconf: command not find,则将 autoreconf 命令的路径添加到项目构建环境中:
    1. 在项目资源管理器中右键单击:查看器 -> 属性 -> C/C++ 构建 -> 环境 -> 添加...
    2. 名称:路径
    3. 值:path_to_autoreconf:${env_var:PATH}
    4. 点击:确定
    5. 点击:应用
    6. 返回第 8 步。
  9. 双击:Project Explorer->viewer->src->viewer.cpp
  10. 添加一些代码:

    包含

    包含

    包括

    int main(int argc, char *argv[]) {

    断言(argc>1);

    CvMat* img = cvLoadImageM(argv1);

    cvNamedWindow("图片", CV_WINDOW_AUTOSIZE);

    cvShowImage("图片", img);

    cvWaitKey(0);

    返回0;

    }

  11. 双击:Project Explorer->viewer->configure.ac,在AC_PROG_CXX下面输入以下代码。

    <块引用>

    AC_CHECK_LIB([opencv_core],[cvSetZero],[],[])

    AC_CHECK_LIB([opencv_highgui],[cvShowImage],[],[])

    AC_CHECK_LIB([boost_regex-mt],[regexecA],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])

    AC_SUBST(BOOST_LIB_SUFFIX)

  12. 双击:Project Explorer->viewer->src->Makefile.am 并输入以下代码。
    >

    <块引用>

    bin_PROGRAMS=查看器

    viewer_SOURCES=openCvFocusIssue.cpp

    viewer_LDFLAGS = -lboost_regex@BOOST_LIB_SUFFIX@ -lopencv_core -lopencv_highgui

  13. 重复步骤 8,autoreconf(重新配置项目)
  14. 单击:Project Explorer->viewer
  15. 通过单击工具栏中的锤子构建项目。如果没有看到锤子,则Window->Open Perspective->Other...并选择C/C++。如果 C/C++ 未显示,请安装 CDT。
  16. 单击:Project Explorer->viewer,然后 Run->Run,然后在 Run As 窗口中->Local C/C++ Application,然后在 Launch Debug Configuration Selection 窗口中->gdb/mi 并按 Enter。您应该看到“Hello World”。
  17. 退出 Eclipse 并导航到查看器项目目录。
  18. 在命令行上,发出 make dist
  19. 确保您有一个viewer-1.0.tar.gz 或类似名称的文件,然后将其删除: rmviewer-1.0.tar.gz
  20. 在命令行上,发出 make clean
  21. 在同一位置,问题 make distclean。
  22. 导航到包含查看器项目的工作区目录。
  23. 将整个查看器目录移动到包含要放置查看器项目的 svn checkout 的目录。
  24. 将目录更改为刚刚移动查看器的位置。
  25. svn 添加查看器 && svn ci -m "已添加 eclipse-autotool 项目"
  26. 打开 eclipse 并确保已安装 SVN 连接器。
  27. 从项目资源管理器视图中删除“查看器”项目。
  28. 打开 eclipse 并将此 SVN 存储库签出添加到 Team 透视图。
  29. 从 SVN 存储库签出导入查看器项目。
  30. 切换回 C/C++ 视角并享受乐趣。

General discussion:

You will need to install Cygwin or something similar to it to make GNU Autotools toolchain available to Eclipse on Windows:
How to deal with Eclipse CDT+Cygwin?

Once your toolchain, Eclipse, with CDT and SVN connectors are ready on your development machines, go through the following steps.

  1. Open Eclipse and switch to CDT: Click Window->Open Perspective->Other... and select C/C++
  2. Select: Eclipse->File->New->C++ Project
  3. Project name: viewer
  4. Select: Project type->GNU Autotools->Hello World C++ Autotools Project
  5. Click: Next
  6. Click: Finish
  7. Right-click in Project Explorer: viewer->Reconfigure project
  8. Click: Console->Display Selected Console submenu-># CDT Global Build Console. If "autoreconf -i" output is nominal, proceed to step 9. If Console reports: sh: autoreconf: command not found, then add the path to the autoreconf command to the Project Build Environment:
    1. Right-click in Project Explorer: viewer->Properties->C/C++ Build->Environment->Add...
    2. Name: PATH
    3. Value: path_to_autoreconf:${env_var:PATH}
    4. Click: OK
    5. Click: Apply
    6. Go back to step 8.
  9. Double-click: Project Explorer->viewer->src->viewer.cpp
  10. Add some code:

    include <opencv/cv.h>

    include <opencv/highgui.h>

    include <cassert>

    int main(int argc, char *argv[]) {

    assert(argc > 1);

    CvMat* img = cvLoadImageM(argv1);

    cvNamedWindow("Picture", CV_WINDOW_AUTOSIZE);

    cvShowImage("Picture", img);

    cvWaitKey(0);

    return 0;

    }

  11. Double-click: Project Explorer->viewer->configure.ac and enter the following code below AC_PROG_CXX.

    AC_CHECK_LIB([opencv_core],[cvSetZero],[],[])

    AC_CHECK_LIB([opencv_highgui],[cvShowImage],[],[])

    AC_CHECK_LIB([boost_regex-mt],[regexecA],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])

    AC_SUBST(BOOST_LIB_SUFFIX)

  12. Double-click: Project Explorer->viewer->src->Makefile.am and enter the following code.
    >

    bin_PROGRAMS=viewer

    viewer_SOURCES=openCvFocusIssue.cpp

    viewer_LDFLAGS = -lboost_regex@BOOST_LIB_SUFFIX@ -lopencv_core -lopencv_highgui

  13. Repeat step 8, autoreconf (Reconfigure project)
  14. Click: Project Explorer->viewer
  15. Build project by clicking the hammer in the toolbar. If you do not see the hammer, Window->Open Perspective->Other... and select C/C++. If C/C++ does not show up, install the CDT.
  16. Click: Project Explorer->viewer and then Run->Run, then in the Run As window->Local C/C++ Application, then in the Launch Debug Configuration Selection window->gdb/mi and press enter. You should see Hello World.
  17. Quit Eclipse and navigate to the viewer project directory.
  18. On the command line, issue make dist
  19. Ensure you got a viewer-1.0.tar.gz or similarly named file, and then remove it: rm viewer-1.0.tar.gz
  20. On the command line, issue make clean
  21. In the same place, issue make distclean.
  22. Navigate to the workspace directory that contains the viewer project.
  23. Move the entire viewer directory to the directory that contains the svn checkout you want to place the viewer project in.
  24. Change directories to where you just moved the viewer.
  25. svn add viewer && svn ci -m "Added eclipse-autotool project"
  26. Open eclipse and make sure that you have an SVN connector installed.
  27. Remove the "viewer" project from the Project Explorer view.
  28. Open eclipse and add this SVN repository checkout to the Team perspective.
  29. Import the viewer project from your SVN repository checkout.
  30. Switch back to the C/C++ perspective and have fun.
朮生 2024-10-01 21:29:34

两个建议:

  • 使用 cmake:我喜欢这个工具。有一点学习曲线,但是
    如果你做对了,所有项目将包含 cmake 文件
    当一个人第一次检查它时,他们运行 cmake 来生成
    他们的 makefile(或 VC++ 项目文件等)具有针对 linux 或 windows 的所有不同规则
    可能需要。

或者

  • 签入项目的基本配置,然后将这些配置添加到 git/svn 忽略中,这样就没有人再次签入它们,然后当您第一次签出时,您必须运行您的配置,但之后它就不会'不被覆盖。

Two suggestions:

  • Use cmake: I love this tool. There is a bit of a learning curve but
    if you get it right all the project will include is the cmake files
    and when a person first checks it out they run cmake to generate
    their makefiles (or VC++ project files, etc) with all the different rules for linux or windows one
    might need.

or

  • Check in a basic config for the project, then add those configs to the git/svn ignore so no one ever checks them in again, then when you checkout for the first time you have to get your config running but after that it won't be overwritten.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文