How to link libraries in Visual Studio Code - c

I have a school project (a mp3 music player) using C and FMOD.
I have a Mac M1 and try to use Visual Studio Code (im bad with C).
I type these lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include"api/core/inc/fmod.h"
int main(void){
printf("hello");
FMOD_SYSTEM* pSystem;
FMOD_System_Create (&pSystem, 0);
}
And I have this error :
Undefined symbols for architecture arm64:
"_FMOD_System_Create", referenced from:
_main in main-b18886.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
But I think Visual Studio Code can't link libraries with fmod.h, I tried the External Libraries add-on for VSC but it's not working, do you have any idea how to figures this out ?

Related

visual code error: how do i fix this problem

I'm super new to coding I have downloaded Visual Studio and as I'm writing my first program I get this error
symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't understand what to do. I have read in come post to see if I have a compiler and I believe I do
Apple clang version 13.0.0 (clang-1300.0.27.3)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
this was my code
#include <stdio.h>`int main() {printf("helloh world");return 0; }
You have a
`
in your code that's not needed and you lack white spaces between your include directive and your function declaration. Try it this way:
#include <stdio.h>
int main() {
printf("helloh world");
return 0;
}

Mac mini m1 + VS Code + C Programming = Not Working

I am self learning to code in C using Mac mini M1 and VS Code. I get the below error:
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please note:
Installed the VS Code Insiders for ARM apple version!
Clang is installed!
Xcode command line tools installed!
C/C++ 1.4.0-insiders2 extension is installed in VS Code!
Code Runner 0.11.4 is installed in VS Code!
Code:
#include <stdio.h>
int main()
{
printf("test");
return 0;
}
Compiled using:
gcc -Wall -Wextra -Werror -o test test.c
Okay! It's because you forget to save your program before executing i.e you should compile and run. Instead of just running it! #Keeplearning!

Error on M1 Mac through GCC Compile in vim

I try to compile C files in vim environment but It occurs on error that
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My command is
gcc [filename.c] -o [filename]
and my file is
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
It is just simple code for checking compile.
But it didn't work.
So I wondering that what is the critical problem that occurs problem.
My command or M1 mac?
Of course I install gcc through 'HOMEBREW'.
Thank you.

Interface from C-Programm in XCode to SWI-Prolog

i want to interface from c-code using XCode IDE under MAC OS X to SWI-Prolog.
I´ve included the header files and use the following sample code:
#include <stdio.h>
#include <SWI-Prolog.h>
#include <SWI-Stream.h>
int main(int argc, const char * argv[])
{
char *av[10];
int ac = 0;
av[ac++] = "/opt/local/lib/swipl-6.2.2/bin/i386-darwin12.2.1/swipl";
av[ac++] = "-x";
av[ac++] = "mystate";
av[ac] = NULL;
#ifdef READLINE /* Remove if you don't want readline */
PL_initialise_hook(install_readline);
#endif
if ( !PL_initialise(ac, av) )
PL_halt(1);
PL_halt(PL_toplevel() ? 0 : 1);
printf("done...\n");
return 0;
}
I also linked at the build settings to the header and lib paths:
Header Search Path: /opt/local/lib/swipl-6.2.2/include
Library Search Path: /opt/local/lib/swipl-6.2.2/lib/i386-darwin12.2.1
But while running the code i get the following errors:
Undefined symbols for architecture x86_64:
"_PL_halt", referenced from:
_main in main.o
"_PL_initialise", referenced from:
_main in main.o
"_PL_toplevel", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone can help me to get my code running?
Thanks in Advance and Kind regards
Solick
Even if you set the correct paths in the settings, it doesn't automatically find the correct library to link with. You have to add the actual library as well.
I work in Ubuntu (and yes, in Windows, still), and I've come to appreciate the pkg-config support.
If you are already comfortable with it, note that when compiled locally, SWI-Prolog generates a directory ~/lib/pkgconfig.
Then you could add that directory to pkg-config configuration, and use the SW with (IMHO) a good support.

Undefined symbols when using ODE in C

I'm trying to use ODE in my C project on Xcode 4.5.1 (MacOS 10.8). I used
./autogen.sh
./configure
make
sudo make install
to install the lib. I then tried to compile a test program:
#include <stdio.h>
#include <ode/ode.h>
int main(int argc, const char * argv[]) {
dWorldID world = dWorldCreate();
return 0;
}
I added dSINGLE in Build Settings->Preprocessor Macros and libode.a in my Xcode project.
When I try to build and run I get a bunch of errors like
Undefined symbols for architecture x86_64:
"std::terminate()", referenced from:
_dJointGroupCreate in libode.a(ode.o)
_dBodyCreate in libode.a(ode.o)
dxJointBall::dxJointBall(dxWorld*) in libode.a(ball.o)
dxJointBall::dxJointBall(dxWorld*) in libode.a(ball.o)
dxJointFixed::dxJointFixed(dxWorld*) in libode.a(fixed.o)
dxJointFixed::dxJointFixed(dxWorld*) in libode.a(fixed.o)
dxJointHinge::dxJointHinge(dxWorld*) in libode.a(hinge.o)
...
.
.
.
.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The very same procedure works fine if I create a C++ project instead of a C one.
Did I forget to add something in the build settings in order to make it work?
Solved adding
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/libstdc++.dylib
to the Xcode project.

Resources