How can I compile Gnu C in windows - c++

Too those who know how, this may be a stupid question, but I'll be asking it anyway because I need some pointers.
The library I'm trying to compile is the SPro toolkit for speech signal processing which is written in (for lack of a better description) Gnu C++
It's a library written for unix and I want to compile it in windows. As much as an object exercise in porting code from, as anything.
Toward that end I have installed code::blocks and a MinGW compiler. I read that I could also use cgywn and that this would be introducing a layer interpreting the gnu c before executing it natively, but let me leave that to the side for the moment.
The first issue I ran into was that the #includes need a little love - ok no problem with that.
But now I find that
scopy.c|462|error: 'SIZEOF_SHORT' undeclared (first use in this function)|
I also installed visual Studio C++ and get the same.
I gather that SIZEOF_CHAR, SIZEOF_SHORT, SIZEOF_LONG, SIZEOF_FLOAT and SIZEOF_DOUBLE would be declared, in a header or somewhere.
Unfortunalty I don't have any idea where, so have no idea what to include to have access to the definitions.
What should I include?
Do I need to define these constants myself as I am in a different environment?
Also I may be barking up the wrong tree, any help is appreciated.

#define SIZEOF_SHORT sizeof(short)
#define SIZEOF_CHAR sizeof(char)
Repeat for all other types.

Related

C++ Windows to Linux - what do I need to know?

I'm a bit stuck on trying to port my code from Windows to Linux. I created a Bluetooth based program, which seems to work in Windows well, that I need to get working in Ubuntu.
Unfortunately the computer with Linux on isn't mine, so I can't have any easy hacks using Wine or other massive compiler altering methods, I really need some advice on porting my code across so it'll be recognised and work in the different OS.
The computer does have code::blocks installed, which from what I understand is fairly useful in converting some things for cross-OS compiling, but I'm not getting too far.
The original code was written in Visual Studio 2013 and understandably it doesn't play nice in code::blocks. I'm getting a lot of 'can't find header' errors, but I don't think simply finding all the missing headers and copying them across will work (will it?).
I need some suggestions on the easiest, stand alone solution for my situation. By standalone I mean I want to get as much of the needed changes and libraries in my project, rather than change/install lots of things on the Linux machine.
I don't really know where to start and searches online don't seem to be too helpful.
Thanks!
First of all, I suggest you examine your Windows code, and use the PIMPL idiom (also here, here, ...) in your classes to isolate all platform-dependent code to separate windows and linux class implementations. Your main platform-independent class then will simply delegate to each implementation at compile time using preprocessor macros to include the appropriate platform implementation header and cpp files.
Beyond this, many runtime functions, as implemented in Visual Studio as either Microsoft-specific, or have been 'modified' and are no longer compatible or even have the same names as the standard ones you will find in linux. For these, you'll need to use a platform.h and platform.cpp file, with separate sections for the two operating systems, containing the missing functions in either macro-defined form (i.e. windows: strnicmp(), linux: strncasecomp() ), or write the missing ones yourself. Example:
// Linux section ...
#ifdef LINUX
#define strnicmp strncasecmp
#endif
The final work involved depends on how many windows-specific calls you have in your code.

What does Boost Wave not do?

Boost Wave provides a reusable C preprocessor. It's easy to obtain from the documentation the (extensive) list of the things it does do, standards it supports, features it includes etc.
What does it not do? Does it support all the nonstandard extensions of GCC and Microsoft C++? Or the various vendor compilers used for embedded systems? How does it fare on the various syntaxes for in-line assembly, or deprecated code from oddball legacy systems? Has anyone tried it on e.g. the full Linux kernel sources or Windows header sets?
Okay, got it compiled and ran a couple of experiments myself. Thus far it appears to not support this GCC extension:
http://gcc.gnu.org/onlinedocs/cpp/Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments
and also barfs on the Microsoft header file C:\Program Files (x86)\Microsoft Visual Studio 11.0\vc\include\xkeycheck.h containing the following construct:
#if defined(auto) /* check C keywords */ \
|| defined(break) \
...
The easiest way to find out if it supports your favorite extension is to just, you know, try it. Is probably even way faster to ask here and wait for enough comments/answers to accumulate to be able to conclude something. Or check the documentation, if it doesn't talk about GCC/MSC extensions at all, it probably just doesn't know of them.

Adding functions erf() and erfc() to math.h _ basics of C .

I am working with the Borland Turbo C++ compiler in a WINDOWS machine, and wrote a piece of code in C.
I want to use the complementary error function erfc() for one of my calculations.
However, when I run the code, the error is
"Linker error: Undefined symbol _erfc in in module filename.c "
The problem here is erfc() and erf() are supposed to be included in the math.h library.
However, these aren't available in mine.
Can anyone please tell me how I can include these functions in my program ?
Thank you
It's likely that you need to pass some special option to link to the math library.
It's also possible that Borland Turbo C++ doesn't support the erfc() function.
In C, the 1990 ISO C standard didn't include the erfc() function. It was added to the language by the 1999 standard. (I'm not sure about C++.) I think that Borland Turbo++ is fairly old.
Try writing a small program that calls sqrt(). If you can get that to work, and erfc() is still unrecognized, then Borland doesn't support it.
In the latter case, either get a newer compiler (there are a number of free ones, and that's probably a good idea in any case), or find an open source implementation of erfc().
You need to link against the math library. On Unix machines this is done by passing the -lm flag to the linker, which means 'link against a library named libm'. There is probably something similar you need to do for Borland, but I'm not sure on the details. Hopefully this will get you headed in the right direction.

Going from Dev-C++ to VC++

Yes, it's a noob question...
I have been using Dev-C++ for all my projects so far, but it is incredibly outdated, and so where the libraries. So I opened up my copy of Visual C++ and copied the code. When I compile, a million errors pop up, as if every second line of my code is shit. I would hate to start the project again from scratch.
Question: Why is it that Dev-C++ and VC++ compile differently??? I've heard they use different compilers, but its still C++. The first error I looked at was an invalid comparison between a const char* and a std::string.
Anyway, is there any way to make VC++ less strict on programming, as is Dev-C++. Or are there a few major differences between Dec-C++ and VC++ compilers that I should know about.
Most of the errors seem to be std::string related, or LPCWSTR (i can fix that myself).
Sorry about this very broad and useless topic, I'm knew.
-Alex
First, a few notes, because many Dev-C++ users are confused (I used to be)
Dev-C++ is not a compiler. The compiler is GCC (or, more precisely, a modified version of GCC so that it runs on Windows : MinGW). Dev-C++ is an IDE : a text editor with an additional button which calls MinGW with the appropriate parameters when clicked.
Nothing more.
Same thing for Visual Studio : Visual Studio is the IDE, which calls the Visual Compiler (vc.exe), which implements VC++, which is Microsoft's implementation of the C++ standard.
Second : It's not a noob question. You have discovered portability issues, which is a great area of frustration in C and in C++. A lot of questions on StackOverflow are due to portability problems (a code that works on Windows but not on Linux, etc).
The general rule of thumb is to 1) set your compiler's warning level to the maximum and 2) develop in parallel on all the platforms you're targetting.
Hope this helps.
This will not answer everything, but it might help.
By default, VC++ uses unicode while MinGW (on which DevCpp is based I believe) uses ansi.
This might explain your issues regarding strings: you're basically passing char* strings where most of the functions require something like wchar*.
I suggest that either you fix your code so it becomes unicode compliant, or that you undefine the UNICODE macro in your VC++ project, if unicode is not required.
As you stated, your old code was C++ and the code is C++ as well, so there shouldn't be that much work... as long as you don't rely on compiler specific behaviors.
Could you give us some samples of things that go terribly wrong ? We might be able to help more accurately.
Are the project settings the same? Perhaps you need to link in additional .libs or add similar preprocessor directives as you had in Dev-C++. If you just copy and paste the code to a project, you're effectively re-setting the project settings all to default, which for many projects, would break the build.
Apart from that - try adding one of the most common errors you receive to the question, with the line of code, and maybe we can comment.
Dev-cpp uses mingw as its compiler. Perhaps you will have more luck using an updated version of mingw, through another IDE. This will help with external dependencies (mingw uses gcc which uses *.a files to link to, VC++ uses *.lib files).
As you mentrion string and LPCWSTR, see ereOn's answer. Make sure you have UNICODE and _UNICODE properly defined (in build flags as -DUNICODE or in VC++ project options).

Name mangling problems when using GNU linker to link to VC++ compiled library

In asking this question, I'm looking for either better understanding of the situation or preferably a solution.
I'm created C++ code and I would like to be able to use the Eclipse CDT IDE rather than Visual Studios, (my workplace is more Eclipse friendly). This implies that, practically speaking, I must use the GNU tool chain to compile my code. For the project at hand, I must link to a library called HyDE.lib that was compiled with the Visual Studios compiler. Of course, the problem that I run into is that the GNU linker can't find the appropriate symbols in HyDE because (I presume) both compilers use different name mangling schemes.
So how do I get around this?
Current thoughts:
The most obvious thing would be to recompile HyDE.lib with the GNU tool chain. This is proving to be more complicated than perhaps it's worth. However there is one avenue that I haven't investigated here. We have a cmake file that supposedly can build to unix... is there some way to have cmake instead use Cygwin GNU? I really know nothing about cmake (and very little about make), so a reference to good information would be nice.
I could connect Eclipse CDT to the Window compiler tools. Yes, but best I can tell this is not easy, and I would potentially lose debugging and maybe even code completion. Then there is Eclipse Wascana, but I read a recent blog that indicated that the Wascana community is waining.
Is there any sort of library demangler-remangler? I imagine a program that I would give a Windows compiled library too, and the program would pick out the symbols, demangle them, and then create a library that had the same symbols, but mangled in the GNU way. At this point I'm making stuff up, so maybe someone could help me better understand name mangling here.
Any ideas?
Unless you place most of the code in HyDE.lib with extern "C" blocks, then your best bet is to recompile it with G++. Even if you do place it in extern "C" blocks, I would still reccomend compiling it with G++ as it usually (but not always) has better support for standards than MSVC.
As an alternative, complete the compilation of the library into a .dll file and use that. Just make sure to put entry points in extern "C" blocks.