help. this programme shows linking error!!! :cry: :cry: :cry:

#include "diction.h"


int Dictionary::find_word(char *s)
{
char word[81];
for (int i = 0; i < nwords; ++i)
if (stricmp(words.get_word(word),s) == 0)
return i;


return -1;
}


void Dictionary::add_def(char *word, char **def)
{
if (nwords < Maxwords)
{
words[nwords].put_word(word);
while (*def != 0)
words[nwords].add_meaning(*def++);
++nwords;
}
}


int Dictionary::get_def(char *word, char **def)
{
char meaning[81];
int nw = 0;
int word_idx = find_word(word);
if (word_idx >= 0)
{
while (words[word_idx].get_meaning(nw,meaning) != 0)
{
def[nw] = new char[strlen(meaning)+1];
strcpy(def[nw++],meaning);
}
def[nw] = 0;
}


return nw;
}

Dani AI

Generated

Common causes and a short diagnosis checklist for the “linking error” in this thread (comments by , and are on the right track).

Linker messages are precise: they usually say “undefined reference” (gcc) or “unresolved external symbol” (MSVC) and include the exact missing symbol. Common roots are: no main() present, a translation unit with needed definitions not being compiled/linked, a declaration that doesn’t match the definition (different parameter types/constness/calling convention), or use of non‑portable C functions (for example stricmp vs _stricmp/strcasecmp). Also look for simple typos in method scope or indexing — a method body that calls get_word on the container without an index will indicate a logic/definition problem that should be fixed.

Quick checklist

  • Copy the exact linker error; the missing symbol name points to the problematic function (constructor, method, or free function).
  • Confirm diction.h declarations exactly match the Dictionary::... definitions in the .cpp (same parameter types, const, and class scope).
  • Ensure every .cpp that defines class methods is compiled and passed to the linker. Example (gcc):
g++ -c diction.cpp
g++ -c main.cpp
g++ diction.o main.o -o dictprog

# or single step
g++ diction.cpp main.cpp -o dictprog
  • On MSVC: cl /EHsc diction.cpp main.cpp

Portable case-insensitive compare: avoid relying on stricmp; use a small std::string-based compare or the platform-specific name.

Minimal test main to exercise the interface (adjust to match the exact declaration in diction.h):

#include "diction.h"
#include <cstdio>

int main()
{
    Dictionary dict;
    char w[] = "example";
    char d1[] = "first meaning";
    char *meanings[] = { d1, 0 };
    dict.add_def(w, meanings);

    char *out[10] = {0};
    int n = dict.get_def(w, out);
    for (int i = 0; i < n; ++i) {
        puts(out[i]);
        delete [] out[i];   // get_def allocates with new[]
    }
    return 0;
}

Notes and cautions

  • Use a proper header guard macro (no dots, use an identifier like DICTION_H). Good point from .
  • If the linker names a specific missing symbol (for example Dictionary::Dictionary() or Dictionary::find_word), that indicates the constructor or that specific method was not linked — check that file was compiled and that the signature matches the header exactly.
  • get_def in the snippet allocates with new[]: match with delete[] to avoid leaks.

The exact linker text plus the full diction.h declarations will pinpoint the cause quickly.

Recommended Answers

All 4 Replies

What's the error? And this looks like just a fragment of the program, as it has no main(). Maybe something else is needed?

yes, a perfectly C program must have a main() function.

yes, a perfectly C program must have a main() function.

Yeah but how do i write the main. I just dont seem to get it???

I am a first year student in c++ but maybe have you tried the create a Header file first with the following

#ifndef diction.h
#define diction.h

your Header file declarations
then add at the end

#endif
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.