Netbeans 项目从 Mac 到 Windows
我在 Mac 中创建了一个 Netbeans CPP 项目并将其上传到 git 中。该项目有使用 Windows 的合作者。
当我将我的项目推送到 github 时,我也推送了 makefile 信息(整个项目)。现在,协作者遇到构建错误,因为引用包含我的 Mac 文件路径。
Windows 机器安装了 cygwin。
- 我该如何解决?
- 我如何使其平台独立?
- 我(和合作者)应该怎样做才能不影响其他工人?
答案:Netbeans 有一个选项(在 c++ 下的项目属性中),可以将文件路径设置为绝对路径或相对路径。所以我所要做的就是设置相对选项并推送更改。该项目开始为每个人工作!瞧!!!!!!!
I created a Netbeans CPP Project in my Mac and uploaded it into git. The project has collaborators who use Windows.
When I pushed my project into github , I pushed the makefile information too (the whole project). Now the collaborators are getting build errors because the reference contains my Mac filepaths.
The Windows machine have cygwin installed.
- How do I resolve it ?
- How I do make it platform independent ?
- What should I (and collaborators ) do to not affect the other workers ?
ANSWER : Netbeans has an option (in the project properties under c++), to have the file path as absolute or relative. So I all had to do was, set the relative option and push the changes . The project started working for everyone ! VOILA !!!!!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Netbeans 有一个选项(在 c++ 下的项目属性中),可以将文件路径设置为绝对路径或相对路径。所以我所要做的就是设置相对选项并推送更改。该项目开始为每个人工作!瞧!!!!!!!
Netbeans has an option (in the project properties under c++), to have the file path as absolute or relative. So I all had to do was, set the relative option and push the changes . The project started working for everyone ! VOILA !!!!!!!!
我发现 NetBeans 为 C++ 生成的项目文件相当笨拙,并且不太易于人类维护。虽然它们确实倾向于从项目的根目录相对引用路径(便于将项目复制到不同的目录),但需要维护的项目文件太多了。如果它们不起作用,你就没事了。
我不知道 NetBeans 是否允许您在项目设置对话框中指定路径的环境变量。据我所知,宏/变量的内容基本上没有记录。但是,如果您知道如何执行此操作,则可以通过环境变量而不是项目设置窗口中的硬编码路径来定义所有文件路径依赖项。远程开发人员只需在其计算机上重新定义环境变量即可。
但我认为更好的解决方案是不使用 NetBeans 从项目设置自动生成的 Makefile。相反,声明您自己的 Makefile 并从“现有 Makefile”创建 NetBeans 项目类型。我发现这非常有效。
然后,您可以在 Makefile 顶部添加一行,如下所示:
其中“common.inc”包含所有与机器相关的硬编码库路径。这是我的一个例子:
然后我的 Makefile 仅通过变量名引用这些目录。因此,当我在具有不同配置的不同机器上移动项目时,我只需要更新 common.inc。
然后,如果其他人想要使用 NetBeans 编译我的项目,他们只需从“现有 Makefile”选项创建一个 NetBeans 项目即可。
I've found that the project files generated by NetBeans for C++ are rather unweildy and aren't very maintainable by humans. And while they do tend to reference paths relatively from the root of the project (facilititating copying the project to different directories), there's just too many project files to maintain. And you're sol if they don't work.
I don't know if NetBeans allows you to specify environment variables for paths in the project settings dialogs. The macro/variable stuff is largely undocumented as far as I can tell. But if you know how to do that, then define all your file path dependencies by an environment variable instead of a hardcoded path in the project settings window. Remote developers need only redefine the environment vars on their machine.
But I think a better solution is to not use the NetBeans auto-generated Makefile from Project Settings. Instead, declare your own Makefile and create a NetBeans project type from "an existing Makefile". I've found that works really well.
Then you can have a line at the top of you Makefile as follows:
Where "common.inc" includes all the hardcoded library paths that are machine dependent. Here's an example of mine:
And then my Makefile only references these directories by variable name. And so when I move the project around different machines with different configs, I just need to update common.inc.
And then if anyone else wants to use NetBeans to compile my project, they just need to create a NetBeans project from "an existing Makefile" option.
相对文件路径的选项实际上不在项目属性中!相反,它位于顶部菜单栏中。选择“工具”,然后选择“选项”,然后单击“C/C++”选项卡,下面的第二个框是“文件路径模式”,选择“始终相对”
The option for relative file paths is actually NOT in the project properties! Instead, it's in the top menu bar.. choose "Tools" then "options" then click the "C/C++" tab, and the second box down is "File path mode" select "always relative"