Solved

ld: Undefined Symbol

Posted on 1997-12-26
1
922 Views
Last Modified: 2006-11-17
I have a C program I have developed that also has a customized library
file.  When I compile (ANSI Compiler on UNIX), I get the following error:

ld:  Undefined Symbol
     _SHPOpen

Where SHPOpen is a library function I have set up in my library file
( <file>.h ) to handle my project.  I don't have any underscores ( _ )
in front of it, yet an underscore shows up when this error returns.

Any suggestions on how to solve this???  Any help would be appreciated...

Thanks,

Terry
0
Comment
Question by:twl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
SvenT earned 100 total points
ID: 1256842
The underscore is added by the compiler to handle external
references. If I understand your problem correct, you want
to make a program consisting of more than one source file.
When you don't link the files correct, you will get a
"ld: Undefined symbol" error.

I send an example which consists of two source files and
one header file (.h). I list the files, compiles one file
to an object (.o) file, compiles the second file and links
them together to form a program and finally executes the
program. I hope this shows how you can solve your problem.

prompt> cat func.c
#include <stdio.h>
#include "shp.h"

int SHPOpen(int i)
{
        printf("Hi, this is SHPOpen. %d\n", i);
        if (i > MY_DEFINITION)
                printf("The parameter %d is larger than %d\n", i, MY_DEFINITION)
;
        return i;
}

prompt> cat main.c

#include <stdio.h>
#include "shp.h"

main()
{
        printf("This is main\n");
        SHPOpen(3);
        printf("This is main again\n");
}

prompt>  cat shp.h
#define MY_DEFINITION 5

extern int SHPOpen(int i);

prompt> cc -c func.c
prompt> cc main.c func.o -o myprogram
prompt> myprogram
This is main
Hi, this is SHPOpen. 3
This is main again
prompt>


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question