The "main" function is defined and included in this compilation for specific needs so, the function that'll become the main for the user will be : void DarkLoop( void )
So, I must then declare it as external. I tried : extern void DarkLoop( void );
but when I compile this, I get this error message :
/SDK/newlib/lib/crtbegin.o in function "_start" (.text+0x14e): undefined reference to 'main' /SDK/newlib/lib/crtbegin.o in function "_start" (.text+0x156): undefined reference to 'main'
Why ?
I MUST include the main() function in my AmiDARK_Engine.o object I compile I MUST declare the DarkLoop() function as external because it will be used by C project that will use AmiDARK Engine.
Anyone have any clue ?
Regards, Freddix/AmiDARK
All we have to decide is what to do with the time that is given to us.
you are trying to link all of your *.o files together this will give you an executable, which is not what you are wanting. Instead once you have all your .of files just run the command "ar" on them like this :
ar cru nameofyour.a file1.o file2.o ... filex.o
No need to delete the .a file each time ar knows how to update a file.
EDIT: IIRC you are using CodeBench, I'm not sure there is a setting to tell you are in fact producing a library (.a) and not an executable...
in fact, consider that all my AmiDARK Engine functions are inside 1 .c file only ! I want to compile this file to make it become a .a file
in that .c file main() exist DarkLoop() does not exist but is called (and then defined as external) because User that will use my .a file will have to create it.
EDIT, I use external MAKEFILE, not the CodeBench system. Based on OpenGL sample makefile: Quote:
# GLUT-fullscreen template # # See GLUT-fullscreen.c and GLUT-fullscreen2.c for details # # written by Hans de Ruiter # # License: # This is provided as-is and can be used and distributed by anyone # without restrictions.
replace [TAB] in the above with a TAB, must be a real TAB not four or eight spaces. (some text editors will do that)
You mention above that main() is in your archive? If that is really what you meant then it shouldn't be. Main should always be in the program. If someone was to write a program with you archive then they would get errors due to your main()
@broadblues concerning main() it's SPECIAL in fact the main is used by my system this way :
Quote:
int main( iny myargc, char** myargv ){ argc= myargc; argv = myargv; DarkENGINE_Start(); // Initialize all plugin from the system DarkLoop(); // Call the user function to start user program DarkENGINE_End(); // Close all plugin, release memories, etc ... return EXIT_SUCCESS; }
So, when you include AmiDARK Engine in a project. You MUSTN'T use main() but DarkLoop() ;) it's exactly what TheGameCreators do with DarkGDK and it work perfectly ;)
Same with your changes in the make file (concerning the last statement I've made
"Make:** no rule ..."
EDIT : Modified with real tab, now I get: ar cru libamiDARK.a AmiDARK_Compilation.o ar: Unknown keyarg 'c' Aborting.
All we have to decide is what to do with the time that is given to us.
EDIT: I've found the problem it's a conflict in files called "ar" in a newcli, if I type ar and validate I get an old ar file from frank wille from 1995 ... Don't know from where this file is and where in my HD it is located.. when I go in GCC folder (AmigaOOS4 SDK), I run ar and cru is well known :)
EDIT#2: I've now compiled my file to a .a lib. I've copied the .a file where the other .a I have added are (like glpng lib :p) I've added : -lAmiDARK at compilation. It seem to find my file I've created a .h file with the definition of my functions in my lib. When I compile, it does not find my library. It tell me that : "undefined reference to ...." with the name of my AmiDARK function and I get this error for all functions I use in the project that exist in the AmiDARK lib.
Edited by freddix on 2009/10/22 8:18:42
All we have to decide is what to do with the time that is given to us.
@freddix to know from where your 'ar' command is try in a cli window: which ar
for gcc to find your library the library must be in a directory where there are the others library or you must tell to gcc where your library is, add -Lpath_to_your_library to the link command (the one that create the executable)
I've fixed the ar pb (I've copied ar from gcc folder in SDK into C: and now it uses the correct ont :p) and cru one too.
Now I can compile my file as .a directly Thank you for the help
but now, when I want to use my .a lib, I get these problems :
I've now compiled my file to a .a lib. I've copied the .a file where the other .a I have added are (like glpng lib :p) I've added : -lAmiDARK at compilation. It seem to find my file I've created a .h file with the definition of my functions in my lib. (.h file included at the beginning of my source code ) When I compile, it does not find my library functions. It tell me that : "undefined reference to ...." with the name of my AmiDARK function and I get this error for all functions I use in the project that exist in the AmiDARK lib.
All we have to decide is what to do with the time that is given to us.
You are not required to put the library in the system library folder (which if you have followed SDK rules, you might have copied it into SDK:local/common/newlib/lib/) you can instruct GCC to search for libraries in additionnal folders than the default ones by adding the option "-L<path>" at the link stage.
So if for example libAmiDARK.a is located in "dir/subdir" you can use the following command line :
gcc example.o another.o -o example -Ldir/subdir -lAmiDARK
Beware IIRC you are using minigl and other libs, don't forget to add them after -lAmiDARK
@abalaban Here is the makefile for the demo that use libAmiDARK.a :
# GLUT-fullscreen template
#
# See GLUT-fullscreen.c and GLUT-fullscreen2.c for details
#
# written by Hans de Ruiter
#
# License:
# This is provided as-is and can be used and distributed by anyone
# without restrictions.
extern void DarkENGINE_Start( void );
extern void DarkENGINE_End( void );
extern int DELoop( void );
extern int main( int myargc, char** myargv );
extern void DESetDisplayMode( int Width, int Height, int Depth );
extern void DELoadImage( const char * FileName, int ImageIndex );
extern void DEMakeObjectBox( int ObjectID, int Width, int Height, int Depth );
extern void DELoadObject( char * FileName, int ObjectID );
extern void DEPositionObject( int ObjectID, float XPos, float YPos, float ZPos );
extern void DEColorObjectEx( int ObjectID, int RGBR, int RGBG, int RGBB );
extern void DETextureObject( int ObjectID, int ImageID );
extern void DESync();
Apparently, all seem to be setup correctly. Where am I wrong ?
All we have to decide is what to do with the time that is given to us.