【理论知识篇】Linux混合编程+log4cpp
由于要使用到log4cpp的库,而log4c的资料是非常的少,也懒得去研究它的用法,于是就决定试试混合编程者玩意。
首先先引用下C++它的father: Stroustrup的一篇文章《C++ Style and Technique FAQ》(http://www2.research.att.com/~bs/bs_faq2.html)里的一小个片段:
Just declare the C function ``extern "C"'' (in your C++ code) and call it (from your C or C++ code). For example:
// C++ code
extern "C" void f(int); // one way
extern "C" { // another way
int g(double);
double h();
};
void code(int i, double d)
{
f(i);
int ii = g(d);
double dd = h();
// ...
}
The definitions of the functions may look like this:
/* C code: */
void f(int i)
{
/* ... */
}
int g(double d)
{
/* ... */
}
double h()
{
/* ... */
}
Note that C++ type rules, not C rules, are used. So you can't call function declared ``extern "C"'' with the wrong number of argument. For example:
// C++ code
void more_code(int i, double d)
{
double dd = h(i,d); // error: unexpected arguments
// ...
}
Just declare the C++ function ``extern "C"'' (in your C++ code) and call it (from your C or C++ code). For example:
// C++ code:
extern "C" void f(int);
void f(int i)
{
// ...
}
Now f() can be used like this:
/* C code: */
void f(int);
void cc(int i)
{
f(i);
/* ... */
}
Naturally, this works only for non-member functions. If you want to call member functions (incl. virtual functions) from C, you need to provide a simple wrapper. For example:
// C++ code:
class C {
// ...
virtual double f(int);
};
extern "C" double call_C_f(C* p, int i) // wrapper function
{
return p->f(i);
}
Now C::f() can be used like this:
/* C code: */
double call_C_f(struct C* p, int i);
void ccc(struct C* p, int i)
{
double d = call_C_f(p,i);
/* ... */
}
If you want to call overloaded functions from C, you must provide wrappers with distinct names for th
相关文档:
Linux Socket 学习(十)
在套接口上使用标准I/O
在前面章节的例子代码中我们已经使用了read(2)或是write(2)系统调用在套接口上执行读取和写入操作。这个规则的一个例外就是recvfrom(2)和sendto(2)函数,这两个函数用来读写数据报。然而,使用read和writte函数调用却有一些程序上的缺点。
这一章我们将会讨论以下内容 ......
最近公司要做linux嵌入式系统,目前主板是采用x86结构。所以就在自己的本本上装了一个虚拟的红旗6。
因为是新手,刚开始的时候认为linux裁剪难的应该是系统内核裁剪,可是一段时间发现不是的。相比之下内核是比较简单的。
内核裁剪主要的工作是你需要什么功能就把对应的模块选上,难点只是英语不容易看懂,要到网上搜索翻 ......
linux裁剪好后,下面紧跟着我就建立图形库。图形库的移植相对来说比较繁琐。因为在相同硬件结构的情况下是可以直接拷贝过来的。我的方法是先把图形库最主要的程序xinit拷过来,然后运行它根据日志提示缺少什么一一移植过来就可以了。一些库文件和一些字体配置,输入输出设备的驱动拷贝过来就可以了,当然内核配置里的frameb ......
我用的是Centos5.4 DVD光盘安装的linux操作系统,安装linux的时候选上开发工具,Xmanager,与数据库相关的包。
操作系统安装完成之后需要进行一系列的配置才能安装oracle10g,下面把主要步骤记录下来。
1.安装完操作系统之后还是有些包没有安装,然而安装oracle10g的时候需要用到,没有安装的包有:
libXp-1.0.0-8.i386.rp ......
Linux系统下的Gcc(GNU C Compiler)是GNU推出的功能强大、性能优越的多平台编译器,是GNU的代表作品之一。gcc是可以在多种硬体平台上编译出可执行程序的超级编译器,其执行效率与一般的编译器相比平均效率要高20%~30%。 Gcc编译器能将C、C++语言源程序、汇程式化序和目标程序编译、连接成可执行文件,如果没有给出可执行文 ......