Thread: LNK error message

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    26

    LNK error message

    Hello,

    I am trying to get a C++ program call a Prolog program (in VS2008 IDE).

    To make all the Prolog header files available to VS2008, I have copied all the include files onto my VC include folder, such as SWI_Prolog.h, SWI-cpp.h, plterm.h, etc.

    However, when I build and compile my program, I get this error:

    error LNK2019: unresolved external symbol _PL_new_term_ref . . .

    I made sure the error is caused by this line:

    goal_term = PL_new_term_ref();

    It wouldn't complain when I put:

    term_t goal_term;

    in my program's header file in the private variables section, but it wouldn't accept this line:

    goal_term = PL_new_term_ref();

    in my main program. Any idea why I get this error message?

    Thank you,

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do you have this Prolog source files? If so, add them to the project.
    If not, then I assume you have a library (ie DLL file)? Then you must also have a .lib file. Add this under linker -> input under project options.

    The why is that you are calling a function that doesn't exist anywhere in your project, but you told the compiler it existed (ie you lied).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Next to the header files (SWI_Prolog.h etc), were there any library files (.a, .lib, .dll) ?

    The header file only tells the compiler what it needs to know to be able to call a function.
    It's the library proper that does the actual work (and is in the domain of the linker).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    26
    I added these lines:

    #pragma comment(lib, "libpl.lib")
    #pragma comment(lib, "plterm.lib")
    #pragma comment(lib, "pthreadVC.lib")
    #pragma comment(dll, "libpl.dll")
    #pragma comment(dll, "plterm.dll")
    #pragma comment(dll, "pthreadVC.dll")

    to my source file, but now I get this error message:

    Unhandled exception at 0x0054870f in myProg.exe:
    0xC0000005: Access violation reading location 0x000000c.

    And then there are two choices of Break and Continue.

    Do I need to add anything else, or this error message is yet another indication that I am doing something (else) wrong?

    Thanks for your help,

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Now you've reached the stage of having a running program.

    But it has a bug in it which causes it to access an illegal memory location.

    Now the fun really starts - debugging!

    Pressing break should drop you in the debugger at the point of the problem. Hopefully from looking around you can figure out what went wrong.

    From the look of things, you've got ptr->someMember where ptr happens to be NULL.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lnk 2005 error in release only
    By harryGrat in forum Windows Programming
    Replies: 1
    Last Post: 02-11-2009, 09:41 AM
  2. Replies: 7
    Last Post: 01-14-2008, 10:25 AM
  3. Arghhhh! LNK 2005 error.
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2006, 09:24 AM
  4. Lnk 1104 Error
    By Bharat_kumarr in forum C++ Programming
    Replies: 6
    Last Post: 09-03-2004, 03:00 PM
  5. LNK error, unresolved external...
    By Brown Drake in forum C++ Programming
    Replies: 3
    Last Post: 10-22-2001, 03:00 PM

Tags for this Thread