Author Topic: Using other .c files to run functions externally?  (Read 654 times)

Mr. Potatobadger

  • Newbie
  • *
  • Posts: 10
    • View Profile
Using other .c files to run functions externally?
« on: December 23, 2016, 05:59:52 am »
Hello!

First off, I want say I'm extremely impressed! This engine is really awesome! I can tell I'll be able to do some really cool stuff with it. I started using it just the other day, and I've picked it up super easily. I've only been able to use it inbetween my job, so I haven't made as much progress as I would have liked.

https://www.youtube.com/watch?v=jzX0Ek00HsI

I've been teaching myself how to use the engine with the demonstrations you see in the video there.

Anyways.

My issue is that I can't seem to use call functions from other .c files inside main.c.

It works just fine in the included Sonic example. In the Sonic example, main.c calls "load_sonic()" from sonic.c, to load sonic's sprite for use. Then "display_sonic()" is called to show sonic's sprite based on the conditions at the time, using variables defined in sonic.h.

I attempted to load a sprite using the exact same method in my project. The problem is, when I call the function I want in main.c to load my sprite, the compiler won't even compile. The compiler closes the second it is opened when I have that function listed. It's very strange! There must be something I'm doing wrong, or something I'm missing.

I'm really hoping you can help me out, Johannes, and I'm confident you can!

Thanks in advance :)

mindslight

  • Administrator
  • Jr. Member
  • *****
  • Posts: 81
    • View Profile
    • Jo Engine
Re: Using other .c files to run functions externally?
« Reply #1 on: December 23, 2016, 09:09:16 am »
Hi Mr. Potatobadger  :),

Thanks for your feedback  ;)

Did you include your file in the makefile like this :

SRCS=main.c my_source.c
include ../Compiler/COMMON/jo_engine_makefile

If yes, make sure that the prototype of the function in "my_source.c" is well known on main.c, otherwise, the compiler with use interger (int) as defaut parameter types & return value.

The easiest way to test it is to declare at the top of "main.c" (after includes) the prototypes like this:

void  my_func_in_source_c(char *param1, int param2, etc);

Hope this will help you :)

PS: Nice demo btw  ;)




« Last Edit: December 23, 2016, 09:11:36 am by mindslight »

Mr. Potatobadger

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using other .c files to run functions externally?
« Reply #2 on: December 23, 2016, 05:08:11 pm »
I completely forgot about the makefile! Including my other file in the makefile is definitely a step in the right direction, haha. However, it still does not compile.

This is my makefile:

Code: [Select]
SRCS=main.c ring.c
include ../Compiler/COMMON/jo_engine_makefile

This is ring.h:

Code: [Select]
#ifndef __RING_H__
# define __RING_H__

#define RING_WIDTH (16)
#define RING_HEIGHT (16)

extern ring_t ring;

typedef struct
{
int ring_anim_id;
} ring_t;

void ring_display(void);
void ring_load(void);

#endif /* !__RING_H__! */

/*
** END OF FILE
*/

And this is my ring.c:

Code: [Select]
#include <jo/jo.h>
#include "ring.h"

ring_t ring;

static const jo_tile ringframes[] =
{
{RING_WIDTH * 0, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 1, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 2, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 3, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 4, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 5, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 6, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 7, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 8, 0, RING_WIDTH, RING_HEIGHT},
{RING_WIDTH * 9, 0, RING_WIDTH, RING_HEIGHT},
};

inline void ring_display()
{
jo_sprite_draw3D2(jo_get_anim_sprite(ring.ring_anim_id), 0, 0, 450);
}

 void ring_load()
{
int sprite_id;

sprite_id = jo_sprite_add_bin_tileset("RING", "RING.BIN", JO_COLOR_Green, ringframes, JO_TILE_COUNT(ringframes));
ring.ring_anim_id = jo_create_sprite_anim(sprite_id, JO_TILE_COUNT(ringframes), 2);
}

I feel like it should work, I'm hoping I'm just missing something obvious, or that I forgot a step.

I don't reference ring.c or ring.h in any way in main.c, and it still will not compile :(

mindslight

  • Administrator
  • Jr. Member
  • *****
  • Posts: 81
    • View Profile
    • Jo Engine
Re: Using other .c files to run functions externally?
« Reply #3 on: December 23, 2016, 05:10:08 pm »
Can you post the error log ?

Mr. Potatobadger

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using other .c files to run functions externally?
« Reply #4 on: December 23, 2016, 10:18:06 pm »
Where do I find the error log?

mindslight

  • Administrator
  • Jr. Member
  • *****
  • Posts: 81
    • View Profile
    • Jo Engine
Re: Using other .c files to run functions externally?
« Reply #5 on: December 24, 2016, 08:46:53 am »
It's the console output of compile.bat.
I need the compiler error message

Mr. Potatobadger

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using other .c files to run functions externally?
« Reply #6 on: December 24, 2016, 11:19:23 pm »
This is what I get:



My makefile is as follows:

Code: [Select]
SRCS=main.c ring.c
include ../Compiler/COMMON/jo_engine_makefile

When I remove ring.c, it compiles just fine.

Mr. Potatobadger

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Using other .c files to run functions externally?
« Reply #7 on: December 30, 2016, 04:30:49 am »
Hello!

I've figured out my issue.

...Kind of.

I'm not really sure what my issue was with that project in particular, but I cloned the backup folder and ported all of my code to the new project. Now it works just fine! I'm pretty sure missing the other file in the makefile was the problem, but I'm still not too sure why it wouldn't work after that.

Regardless, I've got it working now!

mindslight

  • Administrator
  • Jr. Member
  • *****
  • Posts: 81
    • View Profile
    • Jo Engine
Re: Using other .c files to run functions externally?
« Reply #8 on: April 11, 2017, 04:35:44 pm »
 :)

 

Sitemap 1 2 3 4 5 6 7 8 9 
SMF spam blocked by CleanTalk