0

I'm working on a program in which I use PDCurses function move() to shift keyboard cursor position where I need it to be from time to time.

I get all working except for this, as when I go compiling (I'm using Dev-C++) I keep getting the "undefined reference to 'move' " linker error, although the <curses.h> header is included and the library package properly installed via his own .DevPak file (3.2 the latest found release).

In that library, the move function has his prototype defined like int move (int, int); and, in my code, I tried both calling it like move (10, 10); (as integer variables LINES and COLS should be defined in the library as well) and like move (LINES, COLS); after manually defining int LINES = 10, COLS = 10;. I also tried using wmove (which basically does the same thing and has his prototype defined like int wmove (WINDOW *, int, int);), getting the same result.

Why am I getting this error?

(I could post my code, but I do nothing but calling the interested function, so I consider that useless. Anyway I'll do that if you find that useful.)

  • Can you show the line used to link? You might want to move the curses library after the object files. – Michael Petch Nov 05 '15 at 05:44
  • I ask this because there is an issue that seems somewhat similar. Since Dev-C++ usually uses gcc (MinGW I think) it may apply: http://stackoverflow.com/questions/16192087/undefined-reference-to-initscr-ncurses – Michael Petch Nov 05 '15 at 05:52
  • I don't think I got it (sorry, I'm not a very skilled programmer). Which line you want me to post? – Lorenzo Maffii Nov 05 '15 at 06:02
  • I haven't used Dev-C++ in ages. Somewhere in the linker settings youmay have to add `-lpdcurses` to link with pdcurses. Maybe that is what is wrong (I think that still has to be manually set even if you use a DevPak - I could be wrong) – Michael Petch Nov 05 '15 at 06:06
  • Honestly, I didn't think for a minute about that. I never touched that part of compilers (my fault :ashamed:), I ever used standard libs and don't know how to manual link non-standard libs). I'll get infoed about that, thanks for now – Lorenzo Maffii Nov 05 '15 at 06:37
  • What version of Dev-cpp are you using? – Michael Petch Nov 05 '15 at 06:51
  • May I need a .a file to link to the linker? – Lorenzo Maffii Nov 05 '15 at 06:53
  • Correct, likely it will be something like libcurses.a that has to be added to your project (additional linker libraries) It will probably be under the directory where you installed Dev-Cpp somewhere under the lib subfolder (assuming you did install the pdcurses devpack) – Michael Petch Nov 05 '15 at 06:54
  • You likely will have to go to your `project options` (on the `project` pull down menu), select the `directories` tab and then click `library directories` and add a directory like `C:\Program Files (x86)\Dev-Cpp\lib` . That directory should be where _libcurses_ was put. Then click on the `parameters` tab and in the `linker` box manually add `-lcurses` (that has the effect of using libcurses.a). This was how I did it on Dev-Cpp 5.11 – Michael Petch Nov 05 '15 at 07:05
  • I have a libcurses.a file in C:\Dev-Cpp\lib. Hope it's what I'm looking for – Lorenzo Maffii Nov 05 '15 at 07:15
  • Yes, see my last comment. Not sure what version of Dev-CPP you are using. I did get it going here. – Michael Petch Nov 05 '15 at 07:15
  • Aww, sorry... mine is 4.9.9.2. Ok, not that up-to-date. – Lorenzo Maffii Nov 05 '15 at 08:01
  • What if I'd want to add *libcurses.a* to the compiler by default? Will operating by `Tools -> Compiler Options -> Directories` work? – Lorenzo Maffii Nov 05 '15 at 08:10
  • If you want it in all your project yes. You would have to include the directory where libcurses.a resides in Tools / Compiler Options / Directories / Libraries . Then click on `general` tab `Add the following commands when calling the linker` (checkbox should be checked) and then add to the end `-lcurses` . -lcurses will locate the file libcurses.a in the list of directories it has been told to search. That is how it appears in 5.11 (might look slightly different in yours) – Michael Petch Nov 05 '15 at 08:18
  • Thank you so much, very precious help. The linker error is gone :) Anyway, the `move()` function doesn't affect the cursor position yet, even if followed by the `refresh()` one – Lorenzo Maffii Nov 05 '15 at 08:52
  • If you are having problems using specific function with curses you could open a new question with the specifics (and a code sample that demonstrates the issue). – Michael Petch Nov 05 '15 at 09:02

0 Answers0