用g ++编译Windows C ++程序

时间:2010-05-08 01:38:49

标签: c++ g++ compilation

我正在尝试用g ++编译Windows C ++程序。这就是我得到的。

/usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
btree.cpp:1204: error: ‘_TCHAR’ has not been declared
btree.cpp: In function ‘int _tmain(int, int**)’:
btree.cpp:1218: error: ‘__int64’ was not declared in this scope
btree.cpp:1218: error: expected ‘;’ before ‘frequency’
btree.cpp:1220: error: ‘LARGE_INTEGER’ was not declared in this scope
btree.cpp:1220: error: expected primary-expression before ‘)’ token
btree.cpp:1220: error: ‘frequency’ was not declared in this scope
btree.cpp:1220: error: ‘QueryPerformanceFrequency’ was not declared in this scope
btree.cpp:1262: error: expected primary-expression before ‘)’ token
btree.cpp:1262: error: ‘start’ was not declared in this scope
btree.cpp:1262: error: ‘QueryPerformanceCounter’ was not declared in this scope
btree.cpp:1264: error: name lookup of ‘i’ changed for ISO ‘for’ scoping
btree.cpp:1264: note: (if you use ‘-fpermissive’ G++ will accept your code)
btree.cpp:1304: error: expected primary-expression before ‘)’ token
btree.cpp:1304: error: ‘end’ was not declared in this scope
btree.cpp:1306: error: ‘total’ was not declared in this scope
btree.cpp:1316: error: ‘getchar’ was not declared in this scope

我注意到的第一件事就是有一些名为_TCHAR,_int64和LARGE_INTEGER的变量类型,它们可能是Windows的东西。这些可以改变什么,以便它们可以用g ++工作?

另外,如果你知道的其他内容可以转换为g ++,那将会有所帮助。

我从这里得到了代码: http://touc.org/btree.html

4 个答案:

答案 0 :(得分:3)

最简单的答案可能是针对winelib构建它。

最好的解决方案,虽然做了很多工作,但是将#ifdef WIN32块放在所有特定于Windows的东西周围,同样#ifdef LINUX围绕相同功能的linux实现。这可能需要大量的重组和重构。

答案 1 :(得分:3)

从链接页面:

  // the main function is just some code to test the b-tree.  it inserts 100,000 elements,
  // then searches for each of them, then deletes them in reverse order (also tested in
  // forward order) and searches for all 100,000 elements after each deletion to ensure that
  // all remaining elements remain accessible.

如果你完全放弃_tmain,那么你应该最好去。仅使用__int64LARGE_INTEGER以便可以调用QueryPerformanceCounter,并且仅从测试主函数调用{{1}}。看起来代码是相对可移植的C ++,事实上看起来错误只是真正从_tmain开始。

答案 2 :(得分:0)

如果您正在使用_TCHAR,那么您还在代码中使用其他特定于Windows的库。我已经可以看到QueryPerformanceCounter和QueryPerformanceFrequency(我曾经使用的前两个Windows库方法,实际上。=]。)更改类型不会让你在Windows库之外找到匹配功能的下一个阶段。很明显,你的源文件已经超过了一千行,但是你有一个你可以发布的移植代码片段,或者你是否正在尝试做一个大型项目?

答案 3 :(得分:0)

我可能错了,但您不必包含windows.h来构建btree或类似的东西。查找与平台无关的代码,或者只是将所有这些特定于平台的调用删除为QueryPerformanceCounter等等......

或者只是获得另一个好的基于模板的B(或B +)树实现。有很多,如果你愿意,我可以分享我的。