VSCode not importing functions from other files in C language - c

I am going through a C course and got to the point where we #include "myfile.h"
Good news : VSCode finds "myfile.h" and can pull variables from it, such as int myvar=10;
Bad News : VSCode does not seem to identify function definition in the "myfile.c", so extern in myfunction() is seen but not defined.
This results in the following
int i = myfunction();
Compilation Error: undefined reference to 'myfunction';
How can I get VSCode to recognize and use "myfile.c"?

Answer found in ::
undefined reference error in VScode
Basically, I had to compile all my files at once. This required me going into the tasks.json file and modifying it from ${file} to ${workspaceFolder}\*.c
This is better explained in ::
https://code.visualstudio.com/docs/cpp/config-linux

Related

Undefined reference to the function 'check' (GCC compilation in MinGW)

I seem to be getting the rookie error where it says, undefined reference to 'check', as shown below:
This should not be a problem, as I have in fact made a check.h and included in hiker.c, as shown below:
Does anybody know the source of this problem? I have just started using MinGW(as I wanted to learn programming C on Windows).
Here is a picture of the main function. I can add the code too if necessary:
I guess that check function is implemented in a file check.c
You must link that file also, because of your check.h export the prototype to let the compiler know how the check function is structured, but the linker needs the check function code compiled and reachable.
What you need is to compile using a command like this:
gcc -Wall hiker.c check.c -o hiker.exe
Take also note that linker is giving you another error about WinMain#16
This means that you started a windows application project, I guess you must change your project to console project type.

dentry_path_raw not working C

So, I'm trying to compile this code that I have to try and "hide" a file (doing this for my security class) and I can't seem to get it working, it seems that linux/fs.h has removed/depreciated dentry_path_raw? Do you guys know how to fix this by any chance?
magic = dentry_path_raw(fp->f_dentry,filename,INTERNAL_BUFFER_LEN);
and it throws this error on build
error: implicit declaration of function ‘dentry_path_raw’
The error is because you are not including explicitly the header that declares the function and the compiler is 'including' implicitily for you and this throws a warning. You could try to add: #include <linux/proc_fs.h>
More, create_proc_read_entry is a deprecated function. Have a look here

lex prefix undefined symbol yyparse

I am including two diferent lex parsers in my C code so to include the second one defined a Prefix on it:
%option prefix="prep"
When I integrated this one in the global proyect It compiles without errors but on execution, If I try to call prepparse (formerly yyparse) I get this error:
undefined symbol: prepparse
I have tried including an external reference (not quite sure if this is correct):
extern int prepparse(void);
And defining it in the Lex header:
#define yyparse prepparse
But I still get the same error.
Any idea of what I am doing wrong?
I think I got it. I have found I omited one information that has proben important. As I only wanted to alter some tokens and not defining a full language (it is only preparsing) I dind't define a Yacc file, so I was not actually a parser but a Lexer what I had to call. So the command is not preparse but preplex.
I stil don't have it working but I guess it is another different issue.

Is it possible to modify compiler include path for Dymola?

This question is raised due to a situation that I encountered
Say I have these external files and some declarations or definitions in them:
foo1.h
extern void ext_func();
foo1.c
void ext_func(){
....
}
foo2.c
#include "foo1.h"
int Modelica_func(){
ext_func();
}
I defined ext_func() in foo1.c. Then, in foo1.h I declared it to be extern, because I want to use it in foo2.c. Modelica_func() is the function that I will be using in Modelica.
The compiler always throws out error LNK2019 to me complaining unresolved external symbol, I guess it's probably due to the reason that the header file cannot find it's matching c file. I am working in Dymola, and I've put all of these files in WorkingFolder/Sources/Include. But still I got the same error. I want others to see my code, so I cannot use static or dynamic library.
Greatly appreciated if anyone could help me a bit of this. THANKS!
You can find some details in Section 12.9.4 of the Modelica Specification.

Typedefs included, but not functions

I'm writing some code that uses a C library provided by MATLAB (to extract data from *.mat files). In my IDE (Code::Blocks), I've included the folder containing the necessary "mat.h", which is on a network drive. My code recognises types defined in mat.h when I do this, but whenever I call functions from the file I get an "undefined reference" error. This is the same case for the example code MathWorks provides. What sort of problem usually causes this?
#include "mat.h"
int main (void) {
MATFile *pmat; // Compiles only when compiler is told to search in mat.h directory
pmat = matOpen("example_filename", "r"); // Never compiles
return 0;
}
Thanks!
Cameron
"undefined reference" is normally a linker error. It's not a problem of a header file. You need to tell the linker to link MATLAB's library (or a dedicated object) to your program.
No idea how this is done in Code::Blocks though. In the Code:Blocks documentation it is described here.
Have you checked the contents of mat.h? Does it declare matOpen()? Also, does the error occur when compiling or linking? If it's during the link phase, you probably need to reference the library that contains the implementation of matOpen() (a .lib in Windows, or .a in Unix). The .h file only declares the function.

Resources