简体   繁体   English

从Windows在Unix上开发C ++,本机函数调用?

[英]Developing C++ on Unix from Windows, native function-calling?

I'd like to ask a few specific questions regarding writing C++ on Unix as opposed to windows. 我想问一些关于在Unix而不是Windows上编写C ++的具体问题。

  1. In windows, to call native OS functions you usually link to a .dll or include windows.h Likewise, how do you refer to the underlying OS functions in Unix? 在Windows中,要调用本机OS函数,通常会链接到.dll或包含windows.h。同样,如何在Unix中引用基础OS函数?

  2. Is there a reference guide for all the underlying OS functions within Unix? 是否有针对Unix中所有底层OS功能的参考指南? (so that one could see what functions are available). (以便可以看到可用的功能)。

  3. What is the best method to "include" the boost libraries? “包括” boost库的最佳方法是什么? To use an IDE like the eclipse C/C++ version and include boost like one would on windows? 要使用像Eclipse C / C ++版本的IDE并像在Windows上那样包含boost?

Thank you 谢谢

1) There is no single header file. 1)没有单个头文件。 You do not call system calls directly, instead they are generally invoked indirectly through the standard c library like fopen (in the case of fopen, you can also call the underlying function open, but that makes a program less portable). 您不直接调用系统调用,而是通常通过诸如fopen之类的标准c库间接调用它们(对于fopen,您也可以调用底层函数open,但这会使程序的可移植性降低)。 Mentioning which system calls specifically you refer to would help 提及您具体指的是哪个系统调用会有所帮助

2) It sounds like you are a new to development on the Unix platform. 2)听起来您是Unix平台开发的新手。 I highly recommend "Advanced Programming in the UNIX Environment" by Richard Stevens. 我强烈推荐Richard Stevens撰写的“ UNIX环境中的高级编程”。

3) You should get familiar with the make utility. 3)您应该熟悉make实用程序。 Something that is generally hidden on windows by your IDE. IDE通常会将某些东西隐藏在Windows上。 In addition the boost library comes with example programs. 另外,boost库附带示例程序。

  1. There is no single header that you can include to have access to all *nix functions; 您不能包括任何单个标头来访问所有* nix函数; see the corresponding man page in sections 2, 3, or 3p for the relevant function in order to tell which headers and libraries you need. 有关相关功能,请参见第2、3或3p节中的相应手册页,以了解所需的标题和库。

  2. Each *nix tends to follow POSIX or SUS to varying degrees. 每个* nix倾向于不同程度地遵循POSIX或SUS

  3. ... What? ... 什么?

On Unix systems the Unix functions are typically in libc along with the C standard library. 在Unix系统上,Unix函数通常与C标准库一起在libc中。 The compiler automatically links this to your executable, typically as a 'shared library', which is sort of like a Windows DLL, but also not exactly. 编译器会自动将此链接链接到您的可执行文件,通常是作为“共享库”,有点像Windows DLL,但也不完全是。

As for the headers to include... most Unix systems come with the command line man command which allows you to pull up manual pages about various calls. 至于要包含的标头...大多数Unix系统都带有命令行man命令,该命令允许您调出有关各种调用的手册页。 These manual pages generally mention the header you need in order to use a particular function. 这些手册页通常会提到您需要使用特定功能的标题。

There are special functions that are implemented as system calls. 有一些特殊功能可作为系统调用来实现。 For the average C programmer, the fact that a particular function is a system call is an implementation detail. 对于一般的C程序员而言,特定功能是系统调用这一事实是实现细节。 But it's often worth noting exactly which functions these are as they help you understand what the OS does for you, and what's being done by a library you're using. 但是,通常值得确切指出这些功能是什么,因为它们可以帮助您了解操作系统为您执行的功能以及所使用的库正在执行的操作。 This distinction tends to be very difficult to ascertain on Windows. 在Windows上,很难确定这种区别。

Most Unix programmers still use make and command line utilities. 大多数Unix程序员仍然使用make和命令行实用程序。 That means there's no IDE settings or anything. 这意味着没有IDE设置或其他任何设置。 You're going to have to figure out what flags to pass the compiler. 您将必须弄清楚哪些标志可以通过编译器。 This is generally not all that difficult. 通常这并不是那么困难。

Also, most Unix systems do not install software willy-nilly all over the filesystem. 而且,大多数Unix系统不会在整个文件系统上随意安装软件。 If it's an include file that's part of an installed package, it will be in the /usr/include directory. 如果它是包含文件,它是已安装软件包的一部分,它将位于/ usr / include目录中。 This means you will not have to magically divine the locations of the Boost include files. 这意味着您不必神奇地判断Boost包含文件的位置。 They will be in /usr/include along with everything else. 它们将与其他所有文件一起位于/ usr / include中。

And while you might have to figure out exactly which Boost libraries you need (like -lboost_filesystem ), all the Boost libraries will be in /usr/lib , or /usr/lib64 with all the other libraries, so you won't have to figure out where they are. 而且,尽管您可能必须准确确定所需的Boost库(例如-lboost_filesystem ),但所有Boost库都将位于/usr/lib或与所有其他库一起位于/usr/lib64 ,因此您不必弄清楚它们在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM