stdscr function vs _stdscr function -- what's the difference? - c

I am not a C guru. I am trying to compile someone else's C code, and am getting the following error:
Undefined symbols for architecture x86_64:
"_stdscr", referenced from:
_new_line in libsms.a(cstatus.o)
_message in libsms.a(cstatus.o)
the "stdscr" method comes from, I think, both "ncurses.h" and "curses.h". The code seems to be expecting "ncurses.h".
The "ncurses.h" file appears to define "stdscr" (no underscore in the name) whereas the linker is complaining about the symbol "_stdscr" (note the underscore).
I have -lncurses in my compiler flags, and I think that bit is working.
If I change the C source code to refer to the variable as "_stdscr", I get
error: ‘_stdscr’ undeclared
instead.
Can someone please
explain where this underscore is coming from and what it's doing?
help me how to know for sure that the ncurses.h header is being correctly found and referenced?
point me in the right direction for further investigation?

Related

How do I fix collect2 error while compiling an old MUD?

I'm trying to run make on an Ubuntu machine to compile a RoT MUD, but the farthest I've gotten is when I get a collect2: error: ld returned 1 exit status.
This is what comes immediately before the error in the terminal (along with a lot of other similar errors):
/usr/bin/ld: obj/wizlist.o:/home/lucas/Projects/R2b5/src/merc.h:3355: multiple definition of `bllmax'; obj/act_comm.o:/home/lucas/Projects/R2b5/src/merc.h:3355: first defined here
From what I've gathered this means that the header files have variable declarations in them, and that using static is an easy fix, however, I haven't been able to figure out where I should put that keyword in the code to fix this issue. The following is the only mention of bllmax in merc.h:
int bllmax, crbmax, crnmax, srpmax, mngmax;
Here is the program I'm trying to compile.
You need to learn the difference between declaration and definition. A declaration is telling the compiler that the symbol exists somewhere but possibly not here. A definition is telling the compiler that the symbol exists here.
The line you show (without any context) is defining the variables, which means they will be defined in each source file that includes the header file.
What it should do is to declare the variables, which can be done by making them extern:
extern int bllmax, crbmax, crnmax, srpmax, mngmax;
Then in a single source file define the variables (without extern).

Why do I get a linker error while I try to compile a C file?

I've had this error for weeks I already made a post about it but it wasn't very clear.
So I am calling a function from a a header file myBmpGris.h and the functions are implemented on the file myBmpGris.c . Here is my main file:
#include<stdio.h>
#include<stdlib.h>
#include "myBmpGris.h"
int main(){
char * image_name = "image_carre.bmp";
BmpImg image = readBmpImage(image_name);
return 0;
I compile by using ggc main.c and I get this error message :
Undefined symbols for architecture x86_64:
"_readBmpImage", referenced from:
_main in main-1c453a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I read a lot of posts about the same error message but none of the answers seem to apply to my case. I'm kind of desperate because a lot of my programs give me the same error. What should I do ?
You need to tell the compiler about all the code files which contain any of the needed functions.
So if you have until now compiled like gcc main.c, then the simplest way of also getting the other file compiled is gcc main.c myBmpGris.c.
You might want to read up on the other things you can helpfully tell the compiler (and other parts of the building), i.e. the possible commandline parameters. Or use one of the available free programming environments. (I am not going to name any. Just use your favorite search engine on "C IDE free" or similar. The first few hits discuss several, try a few, then use the one your friends use, or the one you really like much, much better.)
There are two thing.
Compilation you have included. h file. It means comilper will make entry in symbol table for all used function from included library.
Linking here linker try to get address from library to fill in symbol table created in first step. This cannot be performed in your case. So give full path of library.

GCC multiple definition of functions linker error

I am trying to create a makefile and was able to get all of the files to compile but it fails on the linker step. Every function in the project is getting an error where it says GCC multiple definition of 'Function Name' then claims that it was first defined in the exact same spot. For example...
project/src/provCreator.o: In function `ProcessArgs':
/home/kevin/project/src/provCreator.c:380: multiple definition of `ProcessArgs'
project/src/provCreator.o:/home/kevin/project/src/provCreator.c:380: first defined here
What are possible causes of this error and how can it be fixed?
Thank you for helping.
Your makefile has project/src/provCreator.c file listed twice. Possibly, with different relative paths.
From your description, it seems that all c files are listed twice (ctrl-c/ctrl-v error?)
Any linker throws a multiple definition error while functions with the same name compiled or same function compiled multiple times due to duplicate listings in makefile. After compilation, while linking linker will be in confusion which object definition it has to link hence it throws an error.
In your case, please check your makefile, probably you might have listed provCreator.c twice.

Error after compiling C code

I get this problem while compiling my code.
Error 14 error LNK2019: unresolved external symbol _findFuncs referenced in function _main H:\pshtoolkit_v1.4-src\whosthere\whosthere.obj whoisthere-alt
What libraries should I link with visual studio in order to resolve the error?
What libraries should I link with visual studio:
The library containing _findFuncs.
OK, not helpful I know, but presumably you know what findFuncs is and you are calling it for a reason. Where did you find out about it? Do you have any documentation?
Maybe you have a typo calling this function (case?), e.g. should it be FindFuncs?
Or is it defined somewhere as a static function?
I have solved the error, it is not the problems with the libraries. The .c file which contains the fincFuncs method had not been properly referenced. Thanks for helping though!
It's actually Linker error which your compiler doesn't resolve that name I think just
do forward declartion for the symbol which you are using in main.
May be you have done forward declaration but missing the definition itself.
Which your linker is looking for
Here it's your function "findfunc"
Check whether it works or not

ld: duplicate symbol _dbg_char

Getting a linker error on osx (no errors on linux or fbsd for the same code):
ld: duplicate symbol _dbg_char in .libs/liboekernel_la-OEK_get.o and .libs/liboekernel_la-OEK.o
the 2 libs listed in the error are mine but the symbol isn't. c++flint confirms '_dbg_char' is in both libs but I'm not sure how to find where it comes from.
tricks, strategies, outright answers for how to id _dbg_char would be greatly appreciated.
project is using libtool/autotools and gcc 4.01
Found a logging / debug macro that was defining dbg_char by 'dbg_ ## t'. fix was to make it static. lessons learned:
osx adds a leading _ to symbol names. it wasn't until i ran nm on linux and saw the same symbol without the leading _ that i thought to search the codebase for "dbg_" instead of "_dbg_"
osx was right to complain
rich irony that cut-and-pasting a debug macro i didn't fully understand caused me so much trouble
You might want to check if both libs #include a header file that declare _dbg_char but miss the extern keyword. Maybe that's #ifdef 'ed out for other platforms so you only hit that problem on OS X.

Resources