gcc undefined reference to `fopen_s' - c

I don't know if I can ask this question again,
There are many duplicates but none of the solutions actually worked for me
I'm using gcc version 4.6.1 (GCC)
And by trying to build I get
undefined reference to `fopen_s'
Please make your suggestions on how I can solve this issue :)
Note: I'm using Windows 7 / 64-bit
Thanks in advance.

Maybe you're not including the file its written in. Not sure where it is but it'd be something like "#include name.h", unless its a function you wrote yourself, in which case you'll need to create a .h file and include it at the top of both this file and the file you wrote that function in, like this " #include "name.h" "

Related

C Include custom header file in Geany on Windows 10 compiling with gcc

I'm having an incredibally hard time finding answers to this for Windows. As if the majority of people use Linux...
Anyways, I need a custom CSV parsing library for C. I found one and downloaded the header file. I tried adding #include <csvparser.h> at the top of my c program but of course, it says file not found. I placed the downloaded file in the same directory as the program.
I think i need to be able to specify an absolute path in the include or place the file csvparser.h in the include directory, but I know how to do neither of these things. What is the default include directory in Windows? I use gcc as my compiler. How can i specify an absolute path in the include statement, on windows? i can find no answer to this.
Thanks!
EDIT
Thank you for the quick reply, I seem to have included the file correctly, but now I'mhaving problems using it.
I found the program at https://sourceforge.net/p/cccsvparser/wiki/Home/
I placed it in the source directory and tried using it, bbut when I try the usage example I'm getting an error. This is my code:
#include <stdio.h>
#include <string.h>
#include "csvparser.h"
#define MAXCHAR 10000
int main() {
// int i = 0;
// file, delimiter, first_line_is_header?
CsvParser *csvparser = CsvParser_new("../MagicProg/Files/MagicProg_csv_ikoria.csv", "|", 1);
return 0;
}
When I try executing this, geany gives me the error:
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Geoff\AppData\Local\Temp\ccsiwJPq.o:hello.c:(.text+0x22): undefined reference to `CsvParser_new'
What am I doing wrong? thanks again
If you're including something that's in your source directory you need to use a different style:
#include "csvparser.h"
The angle-brackets form is exclusively for things found in your include path, not in your source directory. That's reserved for things like OS and compiler headers, as well as system-installed libraries.
I made the huge newb error of not including the src files along with the header file. I blame myself. thanks everyone for help

"undefined reference" error after adding function to a C project

I've added a new function wiringPiVersion() to wiringPi, but after I build and install the shared library, when I attempt to compile a small C program around it, I get:
wpi_ver.c:(.text+0xc): undefined reference to `wiringPiVersion'
However, when I include it in an XS based Perl module, all works well. I don't know enough about C to figure out what's going wrong here, and I've been searching for the better part of two hours trying different things to no avail.
Here's my small C program to test the new function:
#include <stdio.h>
#include <wiringPi.h>
int main (){
char * ver = wiringPiVersion();
printf("wiringPi version: %s\n", ver);
return 0;
}
Compilation that throws the error:
gcc -o ver wpi_ver.c -lwiringPi
The addition to wiringPi's header file:
extern char * wiringPiVersion(void);
The wiringPi's .c file addition:
#define WPI_VERSION "2.36"
char * wiringPiVersion(void){
return WPI_VERSION;
}
In my Perl module's XS file, I have:
char *
wiringPiVersion()
...and my Perl module's Makefile.PL
LIBS => ['-lwiringPi'],
...and after re-installing the Perl module, I can access the function without any issues in a test script.
I'm hoping this is something simple I'm overlooking which someone may be able to point out. My question is, how do I rectify this?
So it turned out that there were two .so files generated when I rebuilt wiringPi... one in the wiringPi's build directory way under my home directory, and the other in /usr/local/lib.
After a tip in comments, I added the library path explicitly:
gcc -o ver wpi_ver.c -L/usr/local/lib -lwiringPi
...and it all fell together and works as expected:
$ ./ver
wiringPi version: 2.36
Note: I have sent Gordon the patch in hopes it gets included in the next wiringPi cut.
Update: I received an email back from Gordon and he stated that currently, only the gpio application has the ability to report the version, so he advised that he's going to add something similar to my patch in a future release.
Although already solved, I added this answer to show what gave me the hint.
Error message "undefined reference" points to a linker error (cf. answer on SO), so its about checking if the correct library is drawn.

PRO*C compile wrong comments

I've a strange behaviour on my pc when a I precompile a .pc source file. I use a command line instruction, like "proc wpd_ric_pla_02.pc wpd_ric_pla_02.c CODE=ANSI_C".
If I compile the very same source file on another machine, with the exact same version of proc (11.1.0.7.0), instead, I have no issue.
I attach an image showing some differences in the .c generated.
You can see on the left the correct .c and, on the right, the .c generated on my machine. SQL instructions are wrongly commented out.
Could someone please help me understand why this happens?
Thank you, Sebastian.
It may have something to do with the file being copied from one machine to the other. But this is only a wild guess.
Maybe the wrong file have some non-visible characters that are messing the compiler.
You can check it by doing a hexdump -c wpd_ric_pla_02.pc if you are in Linux.
If you are using Windows I suggest you use Notepad++ View / Show Symbol / Show All Characters function.
If that doesn't work, try isolting the problem in a single query.

Compilation error on include with ljpeg library in C

I have a project for college, where i need to use libjpeg (C language), to complete 2 codes the teacher gave to us. It's a about transforming a pic into ASCII symbols (like the ASCII draws, you know)
We have a code for reading a jpg and a code for writing a jpg.
The problem is i had to install the libjpeg, i THINK the installation went well but i'm not sure so i have 2 questions
How can i verify libjpeg is correctly installed ? i didn't link it to gcc so i have to use the option for saying to gcc where is jpeg-6b (the folder which contains ljpeg) so i tried this :
Typing "gcc -L/jpeg-6b" the folder is jpeg-6b and it's right on the location where i do the command. i only get an error message about the fact the input is empty (normal ok), i think if the lib was not correctly installed, i should get an error for saying me i can't use the libjpeg version, right ?
In the 2 codes i said the teacher gave to us, she puts #include <libjpeg> on the beginning of it. But i saw on the internet that people use #include <jpeglib.h>, but both of them DON'T work and i get a message telling me :
test.c:1:21: fatal error: jpeglib.h: no such file or directory
#include <jpeglib.h>
is my include bad? or is the libjpeg bad installed ? (i read the doc and i did ./configure then make like it's said)
Just as you add -L/jpeg-6b you need -I/jpeg-6b/path/to/jpeg/headers too. I would recommend a Makefile to automate this.

What is the easiest way to parse an INI File in C?

There are some similar questions about C++, Java and C# so now my question is about C. If I have this config file
[BBDD]
user=**
password=***
database=***
IPServidor=*
port=3***
[Device]
dev=8
Temperatura=5=1001
Humedad=7=1002
Link=8=1003
Volt=9=1004
[Device]
dev=10
Temperatura=5=1012
Humedad=7=1013
Link=8=1014
Volt=9=1015
what is the best way to read the values of Device. I am a linux user. I used glib but I had some problems because there is the same key (Device) so it returns me as the tutorial says only the values of the last Device array. Also Boost as I know has libraries for C++, libconfig also I think is not used for this kind of config files. Finally iniparser has a difficult installation guide for me. Do you think that some solutions like sscanf, fprintf are good?
Finally iniparser has a difficult installation guide for me. Do you think that some solutions like sscanf, fprintf are good?
The iniparser may have a difficult installation, but that's a small tradeoff for code that already works, has already been tested, and handles cases that you haven't thought of.
What problems are you having with using iniparser? I just tried it. I first did make in the iniparser directory, and the code was built. To use the library, I did the following:
gcc test.c ./libiniparser.a
This was because I had created the test program in the same directory as the library. When you include iniparser.h in C++, make sure to do the following:
extern "C"
{
#include "src/iniparser.h"
}

Resources