error LNK2019: unresolved external symbol

I'm getting this error, and I cant find out whats wrong!Sad

Can anyone help me ?

flatetrimming_test error LNK2019: unresolved external symbol _les_pci_entitet referenced in function _pdi_main
This is my code:

#include "stdafx.h"

#include <math.h>

#include <windows.h>

#include <stdio.h>

#include <conio.h>

extern "C"

{

#include <pdi.h>

}

/* Entity digitise mask */

//#define DIG_ALL_ENTS "-255"

//#define DIG_SURF_ENTS "50-61"

//#define DIG_POINT_ENTS "4"

//PROTOTYPER

extern "C"long les_pci_entitet(char* EdgeCam_entitet);

extern "C"void pdi_main(void)

{

//long nId(0);

//short nReturn(DONE);

//DEKLARER GLOBALE VARIABLE HER:

short i;

long idnumber,ent_nummer;

char *ent_navn;

pdi_valid();

/*

switch (pdi_get_execute_status(&nId))

{

case MENU_SETUP:

nReturn = pdi_help_box("Hello World-menusetup");

break;

case MENU_EXEC:

case PDI_EXEC:

nReturn = pdi_help_box("Hello World -exec");

break;

default:

pdi_help_box("Unexpected Status!");

nReturn = ABORT;

break;

}

*/

if ((i = pdi_get_execute_status(&idnumber)) != PDI_EXEC)

{

pdi_error("This PDI must be run from the PDI category");

pdi_end(REDO);

}

//SKRIV INN KODE UNDER HER:

ent_navn = "TPT_23";

//les_pci_entitet(navn); //returnerer "long" entitetno

ent_nummer=les_pci_entitet(ent_navn);

pdi_delete_entity(ent_nummer);

pdi_end(DONE);

}

//*****************************FUNKSJONER************************************************************

long les_pci_entitet(char EdgeCam_entitet)

{

struct ehead h;

struct param_var pci_entnavn;

short funnet=0;

long ent_start,ent_slutt,entitetno;

//********************** Lesing av PCI-variable

// Leser pcivariabel navn p? entitet som det skal kalkuleres p?

memset(&pci_entnavn,0,sizeof(struct param_var));

strcpy((char*)pci_entnavn.name,"EdgeCam_entitet");

pci_entnavn.which=PARAM_STRVAR;

if (!pdi_read_pci_variable(&pci_entnavn))

{

pdi_error("\nx_kalkuler_curve_ekstremal : Feil ved lesing av pci-variable ! ");

pdi_end(ABORT);

}

//ent_start=pdi_get_num_ents(ENTS_STARTUP);

ent_start=20;

ent_slutt=pdi_get_num_ents(ENTS_CURRENT);

for(ent_start=ent_start;ent_start<=ent_slutt;ent_start++)

{

if(pdi_get_header(ent_start,&h))

{

if(!strcmp(h.name,(char*)pci_entnavn.str))

{

entitetno=ent_start;

funnet=1;

break;

}

}

}

if(!funnet)

{

pdi_error("\nflatetrimming_test : Flaten ikke funnet !");

pdi_end(ABORT);

}

//ENTITET ER FERDIG INNLEST I PROGRAMMET

//Entiteten det skal jobbes med har nummer "entitetno" (long)

return entitetno;

}


[6177 byte] By [MildJoe] at [2007-12-16]
# 1
MildJoe wrote:
I'm getting this error, and I cant find out whats wrong!Sad

Can anyone help me ?

flatetrimming_test error LNK2019: unresolved external symbol _les_pci_entitet referenced in function _pdi_main

extern "C" long les_pci_entitet(char* EdgeCam_entitet);

long les_pci_entitet(char EdgeCam_entitet)

{
...
}

If you compile this file as cpp file with les_pci_entitet (/Tp is by default for .cpp files) it would receive C++ mangled name, when you define it as C external. You need to compile file with this function as C code (/Tc or rename extension to .c). If it is in the same same file as _pdi_main, just remove extern "C".

Thanks,
Nikola
VC++

NikolaDudar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
Thanks! it worked fine now.

But I thougt i'd separate it from the main file, and create my own library. Then I ran into a similar problem.

I created this file with the pdi_main :
--

#include "stdafx.h"

#include <math.h>

#include <windows.h>

#include <stdio.h>

#include <conio.h>

#include <pdi.h>

#include <flatetrimming_test.h>

void pdi_main(void)

{
char *entitetnavn;

//pdi_valid();

//SETT INN KODE HER:

entitetnavn="$TPT_23";

les_pci_entitet(entitetnavn);

pdi_end(DONE);

}

This compiles fine, but when I build it returns these 2 errors:

1.: forsterket_nakke2 error LNK2019: unresolved external symbol _les_pci_entitet referenced in function _pdi_main

2.: forsterket_nakke2 fatal error LNK1120: 1 unresolved externals
I've written the function in the file flatetrimming_test.c like this:

#include <pdi.h>

#include <flatetrimming_test.h>

long les_pci_entitet(char* EdgeCam_entitet)

{

struct ehead h;

struct param_var pci_entnavn;

short funnet=0;

long ent_start,ent_slutt,entitetno;

//********************** Lesing av PCI-variable

// Leser pcivariabel navn p? entitet som det skal kalkuleres p?

memset(&pci_entnavn,0,sizeof(struct param_var));

strcpy((char*)pci_entnavn.name,EdgeCam_entitet);

pci_entnavn.which=PARAM_STRVAR;

if (!pdi_read_pci_variable(&pci_entnavn))

{

pdi_error("\nx_kalkuler_curve_ekstremal : Feil ved lesing av pci-variable ! ");

pdi_end(ABORT);

}

ent_start=20;

ent_slutt=pdi_get_num_ents(ENTS_CURRENT);

for(ent_start=ent_start;ent_start<=ent_slutt;ent_start++)

{

if(pdi_get_header(ent_start,&h))

{

if(!strcmp(h.name,(char*)pci_entnavn.str))

{

entitetno=ent_start;

funnet=1;

break;

}

}

}

if(!funnet)

{

pdi_error("\nflatetrimming_test : Flaten ikke funnet !");

pdi_end(ABORT);

}

//ENTITET ER FERDIG INNLEST I PROGRAMMET

//Entiteten det skal jobbes med har nummer "entitetno" (long)

return entitetno;

}

this also compiles fine, but when i build it returns this:

1: flatetrimming_test error LNK2019: unresolved external symbol _pdi_main referenced in function _PdiWndProc@16
2: flatetrimming_test fatal error LNK1120: 1 unresolved externals

then i move the flatetrimming_test.lib file to the "Library Directory" and i make a flatetrimming_test.h file and save it in the "Include" directory.
right?

my .h file is like this:
--

long les_pci_entitet(char* EdgeCam_entitet);

--
Any help is appreciated!!

Thanks,
Joe

MildJoe at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3

It is the same issue, you have just moved code around, but have not fixed the error. The file with pdi_main is still compiled with C++ most likely, otherwise you would get error on stdafx.h, because PCH is most likely is C++.

Here is what I would recommend:
- Do you really need to keep C code? If answer is no, either rename all C files into CPP files or use /TP switch.
- If you need to keep C code, separate C code into .c files (for example, flatetrimming_test.c), remove header files for functions in C files (such as flatetrimming_test.h) and then in your CPP files, add extern "C" <function signature>; (for example, extern "C" long les_pci_entitet(char* EdgeCam_entitet);) And remove any other extern "C" function, because I think the second error caused by a line like extern "C" pdi_main(...). If it is C++ function, you need to just add it definition to .h file, the do #include "myheader.h" in .cpp file and use it.

Hope this clarifies things for you. Try to get any C++ book, most of them cover how to work with C code from C++ code.

Nikola

NikolaDudar at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...