obvious C++ compile/link problem...
I'd image someone can spot the problem in less than
a minute, but I'm (as usual) clueless.
I have the following 3 files in a C/C++ Xcode project
======= texture.h =========
// function declaration (aka prototype)
GLuint load_PNG_texture(char const *textureFile);
========================
======== texture.c =========
// function definition here
#include "texture.h"
GLuint load_PNG_texture(char const *textureFile)
{
// code removed for brevity's sake
}
=========================
======= main.c ==========
#include "texture.h"
// function call
GLuint texId = load_PNG_texture("whatever.png");
========================
The compile is clean except for one warning and one error:
(warning) implicit declaration of function "_load_PNG_texture"
(error) Undefined symbols: _load_PNG_texture
First off, Shouldn't the #include "texture.h" in main.c
be sucking the load_PNG_texture's declaration into main.c?
So why the (warning) saying that it is not found?
I've double checked and (I believe) the signature of the
declaration matches that of the definition and call.
Beyond that, I don't know how to proceed further.
Thanks for any assistance.
P.S. I'm assuming that once the warning is resolved, the
undefined symbol error will take care of itself.
a minute, but I'm (as usual) clueless.
I have the following 3 files in a C/C++ Xcode project
======= texture.h =========
// function declaration (aka prototype)
GLuint load_PNG_texture(char const *textureFile);
========================
======== texture.c =========
// function definition here
#include "texture.h"
GLuint load_PNG_texture(char const *textureFile)
{
// code removed for brevity's sake
}
=========================
======= main.c ==========
#include "texture.h"
// function call
GLuint texId = load_PNG_texture("whatever.png");
========================
The compile is clean except for one warning and one error:
(warning) implicit declaration of function "_load_PNG_texture"
(error) Undefined symbols: _load_PNG_texture
First off, Shouldn't the #include "texture.h" in main.c
be sucking the load_PNG_texture's declaration into main.c?
So why the (warning) saying that it is not found?
I've double checked and (I believe) the signature of the
declaration matches that of the definition and call.
Beyond that, I don't know how to proceed further.
Thanks for any assistance.
P.S. I'm assuming that once the warning is resolved, the
undefined symbol error will take care of itself.
are you sure you're not lying about the extension of main.c? (ie that it's not a .cpp, which'd make a difference)?
does it really have the underscore in the "implicit declaration" warning?
does it really have the underscore in the "implicit declaration" warning?
hm, I could have sworn I replied last night, but I guess I just forgot to press the post button.
Try changing char const to const char.
Try changing char const to const char.
char const * is exactly the same thing as const char *. Your post was deleted because it was just random guessing at the problem, which really isn't helpful.
Bingo! OSC was right on the money. Changed to C++ compiler and the warning
was erased. However, I'm still getting the:
Undefined symbols: _load_PNG_texture
Now, here's what gets me. Isn't the load_PNG_texture() function defined
in the texture.c file! So why isn't the linker seeing it? Is there a trick or
mechnism I can do here? Do I need to restructure my design? What gives?
Thanks.
was erased. However, I'm still getting the:
Undefined symbols: _load_PNG_texture
Now, here's what gets me. Isn't the load_PNG_texture() function defined
in the texture.c file! So why isn't the linker seeing it? Is there a trick or
mechnism I can do here? Do I need to restructure my design? What gives?
Thanks.
ThemsAllTook Wrote:char const * is exactly the same thing as const char *. Your post was deleted because it was just random guessing at the problem, which really isn't helpful.After looking it up, it is the same, but I posted about it because I thought a constant pointer was declared type const * rather than type * const. It wasn't just a random guess, either, since the compiler often does get picky with uses of const. In this case, I guess it wasn't extremely likely for it to complain (and it turned out it didn't), but often it's simple and inconspicuous mistakes that cause errors and warnings. In this case, I figured it was looking for char * or const char *, but not char * const. (since that's the equivalent of what I thought it meant)
On a related note, I would appreciate in the future that you don't delete my posts. If I'm posting about help, I usually only post if I think it's a possible solution. You could just tell me that it's the same and wouldn't help, instead of leaving me scratching my head.
akb825 Wrote:After looking it up, it is the same, but I posted about it because I thought a constant pointer was declared type const * rather than type * const. It wasn't just a random guess, either, since the compiler often does get picky with uses of const. In this case, I guess it wasn't extremely likely for it to complain (and it turned out it didn't), but often it's simple and inconspicuous mistakes that cause errors and warnings. In this case, I figured it was looking for char * or const char *, but not char * const. (since that's the equivalent of what I thought it meant)
On a related note, I would appreciate in the future that you don't delete my posts. If I'm posting about help, I usually only post if I think it's a possible solution. You could just tell me that it's the same and wouldn't help, instead of leaving me scratching my head.
I wasn't actually the one who deleted your post, but just the same, it could have potentially been misleading. Since you didn't actually say anything other than "try this", it looked more like a random guess than a real attempt at help. It's important to really know your stuff before you attempt to help, because misinformation can be as harmful as no information.
Anyway, having your post deleted is nothing to get upset about. It happens quite a bit on this forum.
I understand that some posts should be deleted, but I think that was going a little overboard. But as long as it doesn't happen very often with my posts, I won't make an issue of it.
if you have the function defined in texture.c then texture.h should have:
if that doesn't work you probably forgot to add texture.c to the project
Code:
#ifdef __cplusplus
extern "C" {
#endif
GLuint load_PNG_texture(char const *textureFile);
#ifdef __cplusplus
}
#endif
if that doesn't work you probably forgot to add texture.c to the project
Thanks for the tip! I'm going to add this to my tool box. Works Now.