繁体   English   中英

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

[英]Compiling a Windows C++ program in g++

我正在尝试用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

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

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

从链接页面:

  // 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 ,并且仅从测试主函数调用它。 看起来代码是相对可移植的C ++,事实上看起来错误只是真正从_tmain开始。

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

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

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

暂无
暂无

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

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