Why is uuid_generate_random undefined? As far as I know I am including the uuid library when compiling.
Any advice whats going wrong?
me#me-vm:~/Projects/_Tests/test_cba$ make
g++ -o res main.cpp -Luuid -std=c++11
/tmp/ccRubbJa.o: In function `main':
main.cpp:(.text+0x30): undefined reference to 'uuid_generate_random'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
Simple code:
#include <iostream>
#include <uuid/uuid.h>
int main(int argc, char** argv) {
uuid_t id;
uuid_generate_random(id);
return 0;
}
Using wrong command.Use below
g++ -o res main.cpp -luuid -std=c++11
-L is used to provide location of library
-l is used to provide name library.
Related
I'm having this problem when I'm trying to start my computer camera.
I'm using this code
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv2/videoio.hpp"
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
}
and it shows this error
enter code here
make all
Building target: video
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "video" ./yes.o -lopencv_video
./yes.o: In function `main':
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::VideoCapture(int)'
makefile:44: recipe for target 'video' failed
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::~VideoCapture()'
collect2: error: ld returned 1 exit status
make: *** [video] Error 1
I'm new to Ubuntu and OpenCV, please help.
In my case I could fix this by adding -lopencv_videoio to the g++ compiler.
I am trying to define a macro for the source file from the command line on an ubuntu system using the -D flag .
The source file is:
#include<iostream>
using namespace std;
int factorial(int n){
if(n!=1){
return(n * factorial(n-1));
}
else return 1;
#ifdef DEEPAK
cout<<"hello"<<endl;
#endif
}
int main()
{
factorial(4);
return(0);
}
The command I am typing is:
gcc -Wall -DDEEPAK factorial.cpp -o main
BUT, I am getting the error:
/tmp/cc4Ii5l2.o: In function `__static_initialization_and_destruction_0(int, int)':
factorial.cpp:(.text+0x63): undefined reference to `std::ios_base::Init::Init()'
factorial.cpp:(.text+0x72): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
Any help would be deeply appreciated. Thanks.
You should use g++ instead of gcc in the command, because gcc doesn't link to the C++ STL by default, and hence it gives an undefined reference to std::ios_base.
g++ -Wall -DDEEPAK factorial.cpp -o main
I have got in the same directory 3 files:
hellomake.cu
#include<hellofunc.h>
int main(){
myPrintHelloMake();
return 0;
}
hellofunc.c
#include<stdio.h>
#include<stdlib.h>
void myPrintHelloMake(void){
printf("Hello dummy!\n");
return;
}
hellofunc.h
void myPrintHelloMake(void)
Makefile
CC=/usr/local/cuda-5.5/bin/nvcc
CFLAGS=-I.
hellomake: hellomake.cu hellofunc.c
$(CC) -o hellomake hellomake.cu hellofunc.c -I.
But when I run through terminal make it prints out:
/usr/local/cuda-5.5/bin/nvcc -o hellomake hellomake.cu hellofunc.c -I.
/tmp/tmpxft_000013bf_00000000-14_hellomake.o: In function main':
tmpxft_000013bf_00000000-3_hellomake.cudafe1.cpp:(.text+0x5): undefined reference tomyPrintHelloMake()'
collect2: ld returned 1 exit status
make: * [hellomake] Error 1
What might be the problem?
You could change the filename hellofunc.c to hellofunc.cpp.
If the filename cannot be changed, you could search more information about how to invoke C functions in C++ code.
You should change the name of hellofunc.c to hellofunc.cu. You may also use #include "hellofunc.h".
I am trying to read in a file. I attempt to use ifstream in read() but I get the following error.
undefined reference to std::basic_ifstream<char,
std::char_traits<char> >::basic_ifstream()'
/home/ameya/Documents/computer_science/cs130B/prog2/prog2.cpp:24:
undefined reference tostd::basic_ifstream >::~basic_ifstream()' prog2.o:(.eh_frame+0x6b):
undefined reference to `__gxx_personality_v0' collect2: error: ld
returned 1 exit status make: * [prog2] Error 1
It says undefined reference to ifstream but I included that at the top so, why am I getting that error? Thanks in advance
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ifstream>
using namespace std;
class DepthMap{
public:
int merge(int numbers[]);
int mergehelper(int left[], int right[]);
void read();
};
int DepthMap::merge(int numbers[]){
return -43;
}
int DepthMap::mergehelper(int left[], int right[]){
return -43;
}
void DepthMap::read(){
ifstream inputFile;
}
int main(int argc, char* argv[])
{
DepthMap depth;
printf("Here");
return 0;
}
Here is my Makefile
CXX = g++
CXXFLAGS = -Wall
all: prog2
prog2: prog2.o
clean:
rm -f prog2
#include <fstream> as it should be.
Your g++ seems to be broken. Why do you not install clang?
Here are some suggested corrections for your makefile:
CXX = g++
CXXFLAGS = -Wall
prog2: prog2.o
g++ $(CXXFLAGS) prog2.o -o prog2
prog2.o: prog2.cpp
g++ $(CXXFLAGS) prog2.cpp -o prog2.o
clean:
rm -f prog2
I believe what you're looking for is
#include <fstream>
You are using gcc to compile and link rather than g++. By using the latter it will make sure you link against libstdc++.so without having to explicitly add it.
Seeing your Makefile confirms the above for linking.
Although you define CXX to be g++ that is only used for the implicit rule that compiles the source file. The implicit rule for linking falls back to CC which will probably be gcc. See the Catalogue of Implicit Rules for GNU make.
Possible dup of this or this, but even after trying to dig through the answers for a while, I couldn't resolve this.
While trying to compile following makefile,
all: test
test: constants.h Point.h Point.cpp line_t.h line_t.cpp drawing_t.h drawing_t.cpp clipper_t.h clipper_t.cpp main.cpp
g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp -lglut
I get an error:
g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp
-lglut /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function _start': (.text+0x18): undefined reference tomain'
collect2: ld returned 1 exit status make: *** [test] Error 1
I am new at Makefile. I guess, I am missing something too obvious.
Apparently none your files define a function with the signature
int main();
or
int main(int argc, char *argv[]);