libuvc program does not compile - c++

I'm trying to use libuvc in one of my C/C++ projects. I succesfully compiled and installed both libusb and libuvc from source and when I attempt to compile the following code using gcc:
#include "libuvc/libuvc.h"
int main (int argc, const char **argv) {
uvc_init(NULL, NULL);
}
I get the following error:
Undefined symbols for architecture x86_64:
"_uvc_init", referenced from:
_main in main-de2855.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'm on MacOS High Sierra 10.13.1 x64.

I used the command:
gcc main.c -luvc -o main
and it worked! Adding the -luvc flag solved my problem, but I don't understand why I need to use it. I've never needed flags before when working with other C/C++ dependencies.

Related

VS Code extension coderunner not working properly on macOS

I am new to programming and wanted to setup c++ on my MacBook Air M1 running on macOS Monterey. I followed some online tutorials to download Homebrew, Mingw-64(using Homebrew) and finally installed VS Code and then installed the c++ extension pack and code-runner extension.
However when I tried to run the following code:
#include <iostream>
using namespace std;
int main(){
cout << "helloworld" << endl;
return 0;
}
I got the following 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)
Can somebody please help me out?

ld: symbol(s) not found for architecture x86_64 clang: error:

This is for a Mac using Eclipse
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello, world!!!" << endl;
return 0;
}
Here is the compiler output:
Invoking: MacOS X C++ Linker g++ -o "Lab2" ./secondlab.o
Undefined 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)
make: *** [Lab2] Error 1
All you need to do is configure the C++ Linker correctly under CDT/eclipse one has to enter "sndfile" in the text field found under:
Project->Properties->C/C++ Build->Settings->Mac OS C++
Linker->Libraries->"Libraries -l"
The "-l" gets added to "sndfile" automatically to create "-lsndfile"
It is also important however to point the Compiler to the correct include directory (containing "sndfile.h"). I guess most installations would install this into "/usr/local/include".
For a C++ project in CDT/eclipse, this would need to be entered in
Project->Properties->C/C++ Build->Settings->GCC C++
Compiler->Includes->"Include paths (-l)"
And please do take a look at this thread.

ld: symbol(s) not found for architecture

First of all I want to say I realise this has been asked a dozen times, and I've read countless solutions without any luck so therefore I'm asking again.
I'm using OS X Mavericks 10.9.5, writing in Sublime 3 and compiling using terminal with g++
I'm trying to compile this simple file (test.cpp)
#include <iostream>
#include <SDL2/SDL.h>
int main () {
if(SDL_Init(SDL_INIT_VIDEO)) {
std::cout << "I made it this far" << std::endl;
}
return 0;
}
Compiler line :
g++ test.cpp
This returns the error :
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in test-ebbae4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, I've tried adding a lot of different flags, -m32 only changes the result to throw Undefined symbols for architecture i386: and ld: symbol(s) not found for architecture i386
I've tried different -arch variations, but I can't seem to get it to work. also played around with -l -I flags but I'm not sure I know what they do/how they could help..
Does anyone have a clue what to do next?
EDIT : Some additional information. I've tried using the .framework for SDL2, that didn't change anything, currently I'm using SDL2 installed through compilation of the source. Headers located in usr/local/SDL2
g++ test.cpp
You should specify the SDL library, too:
g++ test.cpp -lsdl2
You might need to include a path if its not well known to the compiler driver:
g++ test.cpp -L/path/to/the/library -lsdl2

GDAL API in C/C++

I'm trying to compile the following program (using GDAL API in C++):
main.cpp:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char *argv[])
{
GDALAllRegister();
GDALDataset* data = (GDALDataset*) GDALOpen( "heightmap.tiff", GA_ReadOnly );
}
the way I build it on a Mac :
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include
and got this:
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include/
Undefined symbols for architecture x86_64:
"_GDALOpenShared", referenced from:
_main in test_gdal-QIB6MK.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What's wrong with this very basic case?
Try to build your project on a Mac using bash file:
#!/usr/bin/env bash
## Path to you installed GDAL
GDAL_PATH=/usr/local/Cellar/gdal2/2.2.0
INCLUDE_PATH=${GDAL_PATH}/include
LIBS_PATH=${GDAL_PATH}/lib
GDAL_LIB=-lgdal
g++ -I${INCLUDE_PATH} -L${LIBS_PATH} ${GDAL_LIB} main.cpp -o main

Whenever I try to link a library I get an error

I'm trying to learn FLTK for C++ and I'm working on a Macbook with the clang++ compiler. Whenever I try to link the library like this:
clang++ -L/usr/local/lib -lfltk
It gives me this error:
clang: warning: argument unused during compilation: '-X11'
Undefined 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've looked on a couple other forums to see how to fix this problem and haven't gotten any answers that worked. I also tried reinstalling Command Line Tools from Apple's Developer site.
You have to make sure you put the linker command (-L/usr/local/lib -lfltk) before doing filename.cpp -o Exectuable but still in the same line in the command line.