Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
57 user(s) are online (40 user(s) are browsing Forums)

Members: 0
Guests: 57

more...

Support us!

Headlines

 
  Register To Post  

(1) 2 3 »
C Extern functions
Quite a regular
Quite a regular


See User information
Hi All,

In Order to make AmiDARK Engine become a .a object that can be included in a C project, I must firstly compile it as a .o object
(if I follow this post : http://www.amigans.net/modules/newbb/ ... hp?forum=25&topic_id=2632 if I'm not wrong.)

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.
Go to top
Re: C Extern functions
Home away from home
Home away from home


See User information
@freddix

Have you allready built your .a static libray with 'ar' ?

What is you compile command?

should be something like

gcc -o test main.c -lamidark

where main.c contains a function main that calls your function.

Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

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

Back to a quiet home... At last
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
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.

CC = gcc
CP = copy
RM = delete
STRIP = strip

OPTIMIZE = -O3
DEBUG =
CFLAGS = -mcrt=newlib $(OPTIMIZE) -Wall -gstabs -DMINIGL

TARGET = AmiDARKEngine.exe

# The source files
SRCS = AmiDARK_Compilation.c

# Flags passed to gcc during linking
LINK =

# Additional linker libraries
LIBS = -lGL -lGLUT -lglpng -lpng -lz

# -------------------------------------------------------------
# Nothing should need changing below this line

OBJS = $(SRCS:.c=.o)

# Rules for building
all: $(TARGET)

$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(LIBS) $(LINK)
$(STRIP) $@.debug -o $@

.PHONY: clean
clean:
$(RM) $(TARGET) $(TARGET).debug $(OBJS)


Regards,
Freddix/AmiDARK.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

set TARGET to value libAmiDARK.a (for example, but prefix 'lib' and suffix '.a' are mandatory).
Then repace the rule
$(TARGET): $(OBJS)
$(
CC) $(CFLAGS) -$(LIBS) $(LINK)
$(
STRIP) $@.debug -$@


by
$(TARGET): $(OBJS)
$(
ARcru $@ $^
RANLIB $@

Back to a quiet home... At last
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@abalaban
don't work.

I get :

MakeFile_Compilation:40:*** missing separator. Stop

EDIT : I use GCC


I have modified file a bit and now compilation progress:

$(TARGET): $(OBJS) $(AR) -cru $@ $^

But at the end of compilation, I get this :
make***No rule to make target 'ar', needed by libAmiDARK.a. Stop

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C Extern functions
Home away from home
Home away from home


See User information
@freddix

The thing that doesn't show in alabalans code above is that there must be a tab infront of the commands.


$(TARGET): $(OBJS)
[TAB]$(AR) cru $@ $^
[TAB]RANLIB $@

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()

Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@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.
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

you should go to newline after $(OBJS), i.e. $(AR) should be on a separate line

Back to a quiet home... At last
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@abalaban
it's now the case with last error statement :

$(TARGET): $(SOBJ)
[
tab]$AR cru $@ $^
[
tab]RANLIB $@


-> ar: Unknown keyarg 'c'


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 9:18:42
All we have to decide is what to do with the time that is given to us.
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

Did you solve your error ?

Back to a quiet home... At last
Go to top
Re: C Extern functions
Not too shy to talk
Not too shy to talk


See User information
@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)

Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@pvanni

maybe you can also use ppc-amigaos-ar instead of just ar I doubt vbcc contains one, you'll then be sure to use the one from gcc.

Back to a quiet home... At last
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@abalaban

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.
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

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 example -Ldir/subdir -lAmiDARK


Beware IIRC you are using minigl and other libs, don't forget to add them after -lAmiDARK

Back to a quiet home... At last
Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@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.

CC     gcc
CP       
copy
RM     
delete
STRIP  
strip

OPTIMIZE 
= -O3
DEBUG 
=
CFLAGS = -mcrt=newlib $(OPTIMIZE) -Wall -gstabs -DMINIGL


TARGET 
libAmiDARK.a

# The source files
SRCS AmiDARK_Compilation.c

# Flags passed to gcc during linking
LINK =

# Additional linker libraries
LIBS = -lGL -lGLUT -lglpng -lpng -lz

# -------------------------------------------------------------
# Nothing should need changing below this line

OBJS = $(SRCS:.c=.o)

# Rules for building
all: $(TARGET)

$(
TARGET): $(OBJS)
    $(
ARcru $@ $^
    
RANLIB $@

.
PHONYclean
clean
:
    $(
RM) $(TARGET) $(TARGET).debug $(OBJS)


I get this at compilation of the demo:
gcc -mcrt=newlib -O3 -Wall -gstabs -DMINIGL   --o AmiDE_3D[MultiCamera].o AmiDE_3D[MultiCamera].c
gcc 
-mcrt=newlib -O3 -Wall -gstabs -DMINIGL -o AmiDE_3D_MultiCameras.exe.debug AmiDE_3D[MultiCamera].-lAmiDARK -lGL -lGLUT -lglpng -lpng -lz
/SDK/newlib/lib/crtbegin.oIn function `_start':
(.text+0x14e): undefined reference to 
`main'
/SDK/newlib/lib/crtbegin.o: In function `_start'
:
(.
text+0x156): undefined reference to `main'
AmiDE_3D[MultiCamera].o: In function 
`DarkLoop':
AmiDE_3D[MultiCamera].c:37: undefined reference to `DESetDisplayMode'
AmiDE_3D[MultiCamera].c:39undefined reference to `DELoadImage'
AmiDE_3D[MultiCamera].c:40: undefined reference to 
`DEMakeObjectBox'
AmiDE_3D[MultiCamera].c:42: undefined reference to `DEPositionObject'
AmiDE_3D[MultiCamera].c:43undefined reference to `DEColorObjectEx'
AmiDE_3D[MultiCamera].c:44: undefined reference to 
`DETextureObject'
AmiDE_3D[MultiCamera].c:46: undefined reference to `DEMakeObjectBox'
AmiDE_3D[MultiCamera].c:47undefined reference to `DEPositionObject'
AmiDE_3D[MultiCamera].c:48: undefined reference to 
`DEColorObjectEx'
AmiDE_3D[MultiCamera].c:50: undefined reference to `DELoadImage'
AmiDE_3D[MultiCamera].c:51undefined reference to `DEMakeObjectBox'
AmiDE_3D[MultiCamera].c:52: undefined reference to 
`DETextureObject'
AmiDE_3D[MultiCamera].c:57: undefined reference to `DESync'
AmiDE_3D[MultiCamera].c:54undefined reference to `DELoop'
make: *** [AmiDE_3D_MultiCameras.exe] Error 1


Here is the demo source code of the demo that'll use my libAmiDARK.a :
/***********************************************************
**
** AmiDARK Engine Development Project
**------------------------------------
**
** Sample : Basic 3D Objects demonstration
** Author : Frederic Cordier
** Date :   2009JUI24-043821
**
************************************************************
*/

/* OpenGL / MiniGL includes */
#include <gl/glut.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* AmigaOS4 specific includes */
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/timer.h>
#include <proto/keymap.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <devices/timer.h>
#include <interfaces/glut.h>

#include "AmiDARK.h"

float XAngle 0.0;

void DarkLoopvoid ){
  
DESetDisplayMode64048032 );

  
DELoadImage"Images/x4.png");
  
DEMakeObjectBox15.05.05.0 );
  
DELoadObject"cube.deo");
  
DEPositionObject10.00.010.0 );
  
DEColorObjectEx1255255255 );
  
DETextureObject1);  

  
DEMakeObjectBox25.05.05.0 );
  
DEPositionObject20.05.0, -10.0 );
  
DEColorObjectEx22550);

  
DELoadImage"Images/Background.png");
  
DEMakeObjectBox5512512512 );
  
DETextureObject5);
  
  while( !
DELoop() ){
    
XAngle XAngle 0.25;

    
DESync();
   }
 }


Here is the AmiDARK.h file :
#ifndef _AMIDARK_H_
#define _AMIDARK_H_
#include <stdio.h>

extern void DarkENGINE_Startvoid );
extern void DarkENGINE_Endvoid );
extern int DELoopvoid );
extern int mainint myargcchar** myargv );

extern void DESetDisplayModeint Widthint Heightint Depth );
extern void DELoadImage( const char FileNameint ImageIndex );
extern void DEMakeObjectBoxint ObjectIDint Widthint Heightint Depth );
extern void DELoadObjectchar FileNameint ObjectID );
extern void DEPositionObjectint ObjectIDfloat XPosfloat YPosfloat ZPos );
extern void DEColorObjectExint ObjectIDint RGBRint RGBGint RGBB );
extern void DETextureObjectint ObjectIDint 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.
Go to top
Re: C Extern functions
Home away from home
Home away from home


See User information
@freddix

It's not complaining that it can't find libAmiDARK. a so that implies that the lib doesn't contain the needed symbols.

Try listing the contents of libAmiDARK.a with

ar t libAmiDARK.a

to make sure it's created properly.

check that you have only one copy of libAmiDARK.a in your libray search path.

If you add -wl,--verbose to your link line you will see where it finds libAmiDARK.a (or not )

Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@freddix

ar t libAmiDARK.a

-> libAmiDARK.o

Correct or not ?

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C Extern functions
Home away from home
Home away from home


See User information
@freddix

Quote:

ar t libAmiDARK.a

-> libAmiDARK.o

Correct or not ?


Well it's what you expect, so that's good.

Try explictly linking with libAmiDark.o instead of the library and see if that works.

like:
gcc -mcrt=newlib -O3 -Wall -gstabs -DMINIGL -o AmiDE_3D_MultiCameras.exe.debug AmiDE_3D[MultiCamera].o libAmiDARK.o -lGL -lGLUT -lglpng -lpng -lz


Try changeing the position of -lamiDark

say:

gcc -mcrt=newlib -O3 -Wall -gstabs -DMINIGL -o AmiDE_3D_MultiCameras.exe.debug -lAmiDark AmiDE_3D[MultiCamera].o -lGL -lGLUT -lglpng -lpng -lz

Go to top
Re: C Extern functions
Quite a regular
Quite a regular


See User information
@broadblues
same if I link with the compiled .o file.

All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post
(1) 2 3 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project