开发者

Compiling a Windows C++ program in g++

I'm trying to compile a Windows C++ program in g++. This is what I get.

/usr/include/c++/4.4/backward/backward_war开发者_JS百科ning.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

The first thing I noticed is that there are these variable types called _TCHAR, _int64, and LARGE_INTEGER, which is probably a Windows thing. What can these be changed to so that they will work in g++?

Also, if there's anything else in here that you know can be converted to g++, that would be helpful.

I got the code from here: http://touc.org/btree.html


From the linked page:

  // 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.

If you ditch _tmain altogether, you should mostly be good to go. __int64 and LARGE_INTEGER are only being used so that QueryPerformanceCounter can be called, and that's only being called from a test main function. It looks like the code is otherwise relatively portable C++, and indeed it looks like the errors only really start in _tmain anyway.


The simplest answer is probably going to be building it against winelib.

The best solution, although much more work, is to put #ifdef WIN32 blocks around all the windows specific stuff, and similarly #ifdef LINUX around the linux implementations of the same functionality. That might require a great deal of reorganisation and refactoring.


If you're using _TCHAR, you're also using other Windows-specific libraries in your code. I can already see QueryPerformanceCounter and QueryPerformanceFrequency (the first two Windows Library methods I ever used, actually. =] ) Changing the types isn't going to get you down the next stage of finding matching functionality outside of the windows libs. Clearly, your source file is well over a thousand lines, but is there a snippet that you're porting that you could post, or are you trying to do a large project?


I may be wrong but you don't have to have windows.h included to build a btree or something like that. Find a platform independent code or simply remove all these platform-specific calls as QueryPerformanceCounter, etc...

Or just get another good template-base B (or B+) tree implementation. There are plenty of them, I can share mine if you want to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜