2

So I have this bit of C++ code to connect to a database server

#include <cstdlib>
#include<stdio.h>
#include "C:\file\path\server.h"



int main(int argc, char** argv) {

    printf("starting");

    short  stat;
    if (login("ServerName", "admin", "secret") == "OK"){
         printf("Good");
     }
    else printf("Bad");

    printf("done");
    return 0;
 }

when I try to compile it I get this error: relocation truncated to fit: R_X86_64_PC32 against undefined symbol `login' Any ideas?

adamH
  • 53
  • 7
  • What does your build command look like? Seems like it cannot link wherever `login` is coming from. Also this `#include "C:\file\path\server.h"` is asking for future trouble. – Fantastic Mr Fox Oct 05 '15 at 22:45
  • Use relative file paths for your include statements. – Trevor Hickey Oct 05 '15 at 22:47
  • I'm making this on my machine for someone to use on another machine with "C:\file\path\server.h" in the same place, hence the full path name, and I'm just using netbeans to compile using cygwin's gcc – adamH Oct 05 '15 at 22:53
  • also I should mention that server.h calls a few of other .h files – adamH Oct 05 '15 at 22:57
  • So where did you define `login`? – Lightness Races in Orbit Oct 05 '15 at 23:26
  • @adamH Is this a C++ question? Or C? In other words, are you compiling with a C compiler or a C++ compiler? The rules about function definitions are different. – vsoftco Oct 05 '15 at 23:26
  • @vsoftco: Not sure why you think it could be C? Title, body, code and tags all say C++. – Lightness Races in Orbit Oct 05 '15 at 23:27
  • As far as I'm aware, it's a C++ question, does gcc compile with c? sorry, I'm new to C/C++ – adamH Oct 05 '15 at 23:28
  • @LightnessRacesinOrbit I wonder what compiler command OP is using. Is it gcc or g++? Because if using gcc, then all C++ bets are off. – vsoftco Oct 05 '15 at 23:30
  • @adamH, can you please post the command you use to compile your code? – vsoftco Oct 05 '15 at 23:32
  • g++ -mcmodel=large and gcc -mcmodel=large both solved my problem, to a degree, but now it's telling me that there's an undefined reference to login, despite it being there – adamH Oct 05 '15 at 23:32
  • @adamH Don't mix gcc and g++, they are not the same! How did they "solve" the problem? Did you also changed the \ to \ \ or /? – vsoftco Oct 05 '15 at 23:34
  • _"despite it being there"_ Where? – Lightness Races in Orbit Oct 05 '15 at 23:37
  • @vsoftco: I don't see any reason to suspect this is anything more than a simple missing function definition. – Lightness Races in Orbit Oct 05 '15 at 23:38
  • the \\ thing didn't make a difference. Those things solved my problem in that I'm now getting a different error message, but it seems like forward progress. And despite it being in one of the provided .h files referenced by server.h. – adamH Oct 05 '15 at 23:40
  • @LightnessRacesinOrbit Yeah probably you're right. @ adamH, make sure you compile the `.cpp` file where the definition of `login` resides. That's the most we can say about your issue. – vsoftco Oct 05 '15 at 23:41
  • the folder that contains all of the .h files are in doesn't have any .cpp files, only .dll and .lib, with very unhelpful names. – adamH Oct 06 '15 at 00:08
  • Sounds like you need to include the lib file that defines login in your build command. – 1201ProgramAlarm Oct 06 '15 at 00:39

0 Answers0