Home Extern Variables seemingly not working
Reply: 0

Extern Variables seemingly not working

user1282 Published in April 27, 2018, 6:43 am

I've been searching through Stackoverflow and the web for the answer and it seems like I'm doing this correctly, however I can't get it to work.

I made a test program for using extern, (it's on xCode using the projects feature if that makes a difference). I'm trying to declare a variable, that I can access anywhere in my program, whenever I change the value of that variable, I want to be able to access the changed value.

What I've done so far is I have a header file


and a


and of course my main.c

In externFile.h I defined:

 extern int ply;

In main.c I have:

int main()
   int ply;
   ply = 5;

In externFile.c I have:

 void printPly(){
 printf("%d is ply.\n", ply);

However I'm getting this error:

 _ply referenced from _printPly
 ld symbols not found for architecture x86_64

Does anyone have any sort of ideas about this?

EDIT: Thanks for the help Weathervane and Eugene!

The problem was that I defined ply inside of main(), instead of outside of the function.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312626 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO