linux到windows移植

来源:互联网 发布:seo页面优化靠谱 编辑:程序博客网 时间:2024/05/08 09:54
windows下一般建的是控制台应用程序,由于使用的库都是跨平台库的,所以移植起来也比较轻松。


问题:msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string
解决方法(alglib表示你使用的某一个库):This is more of a conflict between alglib and the STL. Alglib uses the STL string and when linking it to part of your code which uses string then it will find another set of objects for string and come up with a problem.
If you are sure that alglib was built using the same version of the compiler that you are using then there is a way around it, but I'm hesitant because it can cause problems. But the thing you can try is to set the linker to allow multiply defined symbols. 
You can set this by going to Project 
Properties->Configuration Properties->Linker->Command Line and in the Additional Options box type /FORCE:MULTIPLE.
This isn't something I recommend though, so do testing to make sure that it works fine.


注意对lib的使用,如:
apr
boost
openssl
tbb
xercesc
zlibc
1.动态库:编译的时候需要.h, .lib, 运行的时候要.dll,注意路径;
2.静态库:编译和运行只需要.h, .lib。
配置属性->C/C++->预处理器->预处理器定义:代码中用到的预编译宏;
配置属性->C/C++->常规->附加包含目录:引用库的头文件路径;
配置属性->链接器->常规->附加库目录:库(.lib)所在的目录;
配置属性->链接器->输入->附加依赖项:库的名字(如:log4cxx.lib);
运行时dll需要放在工程目录下或者可执行程序的目录或者系统目录下。
error LNK2019: 无法解析的外部符号,对库的使用不正确造成的。


头文件, 函数的不同,可以用如下宏,预处理:
#ifdef WIN32
  // windows handle
#elif __linux__
  // linux handle
#else
  // others handle
#endif


如果两个函数参数和返回值都相同时,如在windows下没有sleep,会使用宏里面定义的Sleep。
在linux下由于定义了sleep这样就不会用到这个宏了,它会调用linux下的sleep函数。
#ifndef sleep
#define sleep(seconds) (Sleep((seconds)*1000))
#endif


windows        替代     linux
localtime_s             localtime_r
inet_addr               inet_pton
GetTickCount            GetTickCount
Sleep毫秒               sleep秒
_mkdir                  mkdir
memset                  bzero
_fullpath               realpath


注意linux、windows下读取的文件格式问题:
在windows下读取配置文件失败,
可能配置文件格式不正确,将utf8改为GB2312;