Problem Building Using Rlyeh's Minimal Lib


Dave18

Member
Joined
Mar 16, 2003
Messages
352
Age
50
Hi

I've tried setting up a simple dev environment in codeblocks to compile using Rlyeh's minimal library. I've tried to test it using the images example that comes with the library. I'm trying to compile it using arm-linux-g++.exe using the linker options -static -lpthread -lm, however when I try to build it I get the following error.

C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\main.cpp||In function 'int main(int, char**)':|
C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\main.cpp|45|error: 'gp2x_image_free' was not declared in this scope|
C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\main.cpp|66|error: 'gp2x_image_free' was not declared in this scope|
||=== Build finished: 2 errors, 0 warnings ===|

I haven't made any changes to images.c, minimal.c (and I can see said function in this file) or minimal.h. It's the same environment I use for SDL stuff (just changed the linker options) and SDL builds without a problem.

Grateful for any pointers.

Dave
 
Rlyeh

Thanks, that's fixed the original issue. I'm still having a compile error though with the following error message:

.\obj\GPL_GP2X\Release\minimal.o||In function `gp2x_sound_play':|
minimal.c:(.text+0x21b8)||undefined reference to `gp2x_sound_frame'|
||=== Build finished: 1 errors, 9 warnings ===|

If I comment out the call to gp2x_sound_frame within gp2x_sound_play it compiles fine but I can't see what the actual problem is.

Dave
 
The problem is that your supposed to define 'gp2x_sound_frame' yourself and put your sound code in there.
 
Squidge

The code I'm compiling is the images.c example code, It contains the line:
void gp2x_sound_frame(void *blah, void *buff, int samples) {}

I assumed this was in there as a dummy sound function to enable the code to compile but for some reason it doesn't seem to work.

Dave
 
try changing it to:

extern "C" {
void gp2x_sound_frame(void *blah, void *buff, int samples) {}
};
 
That changes the error message to:

C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\main.cpp||In function 'void gp2x_sound_frame(void*, void*, int)':|
C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\minimal.c|2512|error: previous declaration of 'void gp2x_sound_frame(void*, void*, int)' with 'C++' linkage|
C:\Users\Dave\Documents\Source Code\GP2X\Minimal Test\main.cpp|23|error: conflicts with new declaration with 'C' linkage|

||=== Build finished: 2 errors, 6 warnings ===|



Dave
 
Ok, lets try surrounding the #include in the same way :

extern "C"
{
#include "minimal.h"
};

That should solve the conflict.
 
If you're confused oin how to mix C and C++ together, made codeblocks can be set to fire gcc up in C mode rather than C++ mod by default. (ie: gcc instead of g++ being the usual first way)

jeff
 
or he could of just renamed his main.cpp to main.c, or minimal.c to minimal.cpp :)

However, I guessed he was using a .cpp extension for a reason, and it bad form to modify other code without good reason, hence the C linkage specification.
 
The main problem was that I copied the source into a blank template which happened to be called main.cpp.

I didn't particularly need to use C++ as I was only testing compiling Rlyeh's tutorial but I wasn't really aware of how much difference there was in the C++ compiler other than the introduction of object orientation.

I learned to code using languages where the compiler workings were hidden away and didn't need to be touched, as such I didn't have a problem learning the C/C++ language but I never really understood the whole toolchain thing other than the basic concept that you compile your code into objects and then link them into a final executable. I guess I should really make the effort to read up on it all (I did have a quick google but I couldn't find a simple explanation) rather than taking the easy option and relying on the incredible helpfulness of this community.

Thanks again for the help, and I understand a bit more than I did a few days ago! :)
 
One of the big differences is "name mangling" or "name decoration" (Google those strings for more info). On a C compiler, this is very simple, its usually either "use the exact name in the source file", "prepend an underscore to that name" (cdecl) and sometimes even add other characters such as @ to indicate a unique address (The last one is more common on Windows using Microsoft products). On a C++ compiler, it's very much different, as the same name can mean many different things (eg, due to operator overloading, classes and namespaces). So a typical C++ name can be for example "5@Classes@TPersistent@Assign$qqrp19Classes@TPersistent". Needless to say, this makes function calls between the languages difficult, and the easy way to make it simpler is to declare functions so they use the same decoration, and thus the linker can find them.
 
Back
Top