This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
Trying to make a c++ program splitting a line and creating 2 std::vector to save elements from said line.
This is the function I call:
void readConf(const char *name, std::vector<t_objectLibrary> libs, std::vector<IObject *> &objs, std::vector<IObject *> &timer)
I placed in inside config.hpp which has it's prototype :
void readConf(const char *name, std::vector<t_objectLibrary> libs,std::vector<IObject *> &objs, std::vector<IObject *> timer);
and in the main I call it like this :
int main(int ac, char **av)
{
std::vector<IObject *> objs;
std::vector<IObject *> timer;
std::vector<t_objectLibrary> libs;
libs = lib_read("./src/objectLibrary");
readConf("config.txt", libs, objs, timer);
...
}
yet I get this error message when I compile with the Makefile. Everything is fine until the last message of compilation it says this :
Here is the Makefile I use (Asked in the comments) :
11 │ SRC = src/getvalue.cpp \
12 │ src/iobject.cpp \
13 │ src/attributes.cpp \
14 │ src/dynamic_lib.cpp \
15 │ src/config.cpp \
16 │ src/color.cpp \
17 │ src/main.cpp
18 │
19 │ OBJ = $(SRC:.cpp=.o)
20 │
21 │ NAME = conf
22 │
23 │ CXX = g++ -std=c++11 -Wall -Wextra -lsfml-graphics -lsfml-window -lsfml-system -fPIC
24 │
25 │ RM = rm -f
26 │
27 │ all: $(NAME) $(OBJ)
28 │
29 │ $(NAME): $(OBJ)
30 │ $(CXX) $(OBJ) -o $(NAME) -ldl
31 │
32 │ clean:
33 │ $(RM) $(OBJ)
34 │
35 │ fclean: clean
36 │ $(RM) $(NAME)
37 │
38 │ re: fclean all
39 │
40 │ .phony: all clean fclean re
The function signature in the hpp doesn't exactly match that in the declaration.
For further reading, consider another SO thread.
In your case, perhaps, a typo (check method signature in hpp).
hth
Related
I am working on a dataframe in julia and one column has zipcodes. In certain instances, a State code is appended in front of zip code.
For example: if zipcode is 123456, and state is ab, it looks like ab 123456.
There are multiple values like that in the column. How can I replace all "ab " with "" in that column.
You can use replace function with a regexp matching your pattern and broadcast it over all entries of the column like this:
julia> using DataFrames
julia> df = DataFrame(x = ["ab x", "y", "ab z"])
3×1 DataFrame
Row │ x
│ String
─────┼────────
1 │ ab x
2 │ y
3 │ ab z
julia> df.x .= replace.(df.x, r"^ab " => "")
3-element Vector{String}:
"x"
"y"
"z"
julia> df
3×1 DataFrame
Row │ x
│ String
─────┼────────
1 │ x
2 │ y
3 │ z
I am using the following pseudocode from the wikipedia page to implement iterative deepening depth-first search for graphs
function IDDFS(root)
for depth from 0 to ∞
found ← DLS(root, depth)
if found ≠ null
return found
function DLS(node, depth)
if depth = 0 and node is a goal
return node
if depth > 0
foreach child of node
found ← DLS(child, depth−1)
if found ≠ null
return found
return null
Here is my code:
bool DLS(GrapheMat* graphe, Node* source, NomSom but, int limit) {
bool found = false;
printf("%s\n", (char*)source->etat);
if (strcmp((char*)source->etat, (char*)but) == 0) {
return true;
}
if (limit > 0) {
List* listSon = nodeSon(graphe, source);
while(!listEpmty(listSon)) {
Node* son = (Node*)popList(listSon);
if (DLS(graphe, son, but, limit-1)) {
return true;
}
}
}
return false;
}
bool IDDLS (GrapheMat* graphe, NomSom goal, int limit) {
bool found = false;
node* source = createNode(graphe, graphe->nomS[0]);
for (int i = 0; i <= limit; i++) {
printf("/nLimit : %d\n", i);
DLS(graphe, source, goal, i);
}
return false;
}
I am using the following graph to test :
It's built from the following file:
A B C D E F G H I J ;
A : B (140) C (118) D (75) ;
B : A (140) E (99) F (151) G (80);
C : A (118) ;
D : A (75) F (71) ;
E : B (99) H (211) ;
F : D (71) B (151) ;
G : B (80) I (146) J (97) ;
H : E (211) J (101) ;
I : G (146) J (138) ;
J : G (97) H (101) I (138) ;
Calling IDDLS(graphe, "J", 4) outputs the following:
/nLimit : 0
A
That's all.
Calling DLS(graphe, "A", "J", 4) outputs the following (newlines removed):
ABABAEFGCADAFEBAEFGHEJ
From what I understand, the DLS function should actually follow the following path:
ABEGHCDEFGHIJ
DLS(graphe, "A", "J", 4) is taking the right path. ABABAEFGCADAFEBAEFGHEJ is correct.
4 3 2 1 0
A A
├─ B B
│ ├─ A A
│ │ ├─ B B
│ │ │ ├─ A A
│ │ │ ├─ E E
│ │ │ ├─ F F
│ │ │ └─ G G
│ │ ├─ C C
│ │ │ └─ A A
│ │ └─ D D
│ │ ├─ A A
│ │ └─ F F
│ ├─ E E
│ │ ├─ B B
│ │ │ ├─ A A
│ │ │ ├─ E E
│ │ │ ├─ F F
│ │ │ └─ G G
│ │ └─ H H
│ │ ├─ E E
│ │ └─ J J
C F
D G
In IDDLS, replace
DLS(graphe, source, goal, i);
with
if (DLS(graphe, source, goal, i)) {
return true;
}
There's no need to keep looking deeper once you've found the node.
The only way IDDLS(graphe, "J", 4) could output what you say it does is if the program was killed by a signal (e.g. from SIGSEGV)[1]. Verify this (by checking the process's exit code). If that's the case, there's a problem with the functions DLS calls, or there's a problem with how it calls them.
You have a memory leak. The List created by nodeSon is never freed.
Optimized to remove needless string comparisons:
bool DLS(GrapheMat* graphe, Node* source, NomSom but, int limit) {
printf("%s\n", (char*)source->etat);
if (limit) {
List* listSon = nodeSon(graphe, source);
while (!listEpmty(listSon)) {
Node* son = (Node*)popList(listSon);
if (DLS(graphe, son, but, limit-1)) {
return true;
}
}
return false;
} else {
return strcmp((char*)source->etat, (char*)but) == 0;
}
}
bool IDDLS(GrapheMat* graphe, NomSom goal, int limit) {
node* source = createNode(graphe, graphe->nomS[0]);
for (int i = 0; i <= limit; ++i) {
printf("/nLimit : %d\n", i);
if (DLS(graphe, source, goal, i)) {
return true;
}
}
return false;
}
Well, it's also possible one of the functions you call calls exit, performs a long jump, or does something similarly weird.
I'm running into a problem using RInside vs the console. This is all run on ubuntu 14.04 using R 3.2.4 installed via apt-get from CRAN. Here is the c++ and R code:
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
R.parseEval("source('abline.R')");
}
abline.R
bp <- data.frame(
age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)
bp.lm <- lm(systolic ~ age)
plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)
The R code works fine from the console, but errors when the program is run.
mlilback#rc2x:/tmp/abtest$ ./abtest
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
what(): Error evaluating: source('abline.R')
Aborted (core dumped)
The if (noInt) { is from the source of abline (line 18 in my version of R). I'm completely stumped as to why this only happens via RInside.
Any ideas?
Works for me without any issues. Ubuntu 16.04. Running out of the examples directory to get the GNUmakefile-based build for free:
~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
-I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
-Wno-unused -Wall soquestion.cpp -Wl,--export-dynamic -fopenmp \
-L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lblas -llapack \
-L/usr/local/lib/R/site-library/RInside/lib -lRInside \
-Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$
I literally just copied an pasted your two files. Also:
~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$
You probably want to open a device file via pdf() or png() ...
I'm new to OCaml and I am a little confused about Modules.
I tried to implement a really simple test but I can't compile it...
Here are the files (I'm on Linux by the way) :
main.ml
let main () =
if ((Array.length Sys.argv) > 2 && int_of_string Sys.argv.(1) > 1 && int_of_string Sys.argv.(2) > 1)
then
begin
Printf.printf "Args = %d && %d\n" (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2));
Laby.initLaby (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2))
end
else
Printf.printf "Usage : ./test x y n"
let _ = main ()
Laby.ml
let initLaby (x : int) (y : int) =
let testCell = Cell.initCell 0 1 in
begin
Printf.printf "Init Laby with X(%d) / Y(%d)\n" x y;
Cell.printCell testCell;
end
Cell.ml
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL =
struct
type t = (int * int)
let initCell (x : int) (y : int) =
(x, y)
let printCell (x, y) =
Printf.printf "Cell -> X(%d) / Y(%d)\n" x y
end
Cell.mli
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL
And here is the Makefile :
NAME = test
ML = Cell.ml \
Laby.ml \
main.ml
MLI = Cell.mli
CMI = $(MLI:.mli=.cmi)
CMO = $(ML:.ml=.cmo)
CMX = $(ML:.ml=.cmx)
OCAMLDPE = ocamldep
CAMLFLAGS = -w Aelz -warn-error A
OCAMLC = ocamlc $(CAMLFLAGS)
OCAMLOPT = ocamlopt $(CAMLFLAGS)
OCAMLDOC = ocamldoc -html -d $(ROOT)/doc
all: .depend $(CMI) $(NAME)
byte: .depend $(CMI) $(NAME).byte
$(NAME): $(CMX)
#$(OCAMLOPT) -o $# $(CMX)
#echo "[OK] $(NAME) linked"
$(NAME).byte: $(CMO)
#$(OCAMLC) -o $# $(CMO)
#echo "[OK] $(NAME).byte linked"
%.cmx: %.ml
#$(OCAMLOPT) -c $<
#echo "[OK] [$<] builded"
%.cmo: %.ml
#$(OCAMLC) -c $<
#echo "[OK] [$<] builded"
%.cmi: %.mli
#$(OCAMLC) -c $<
#echo "[OK] [$<] builded"
documentation: $(CMI)
#$(OCAMLDOC) $(MLI)
#echo "[OK] Documentation"
re: fclean all
clean:
#/bin/rm -f *.cm* *.o .depend *~
#echo "[OK] clean"
fclean: clean
#/bin/rm -f $(NAME) $(NAME).byte
#echo "[OK] fclean"
.depend:
#/bin/rm -f .depend
#$(OCAMLDPE) $(MLI) $(ML) > .depend
#echo "[OK] dependencies"
Here is the output of the Makefile :
[OK] dependencies
[OK] [Cell.mli] builded
[OK] [Cell.ml] builded
File "Laby.ml", line 3, characters 17-30:
Error: Unbound value Cell.initCell
Makefile:47: recipe for target 'Laby.cmx' failed
make: *** [Laby.cmx] Error 2
I think it's a compilation error, since it seems to not found the Cell module, but I can't make it works...
What am I doing wrong, and how can I fix it?
Each .ml file serves as its own module. You seem to have module Cell inside cell.ml which is double. You would have to address that function as Cell.Cell.initCell. Or open Cell in laby.ml. Also, I think .ml file names are conventionally lowercase? Aside: why does make output wrong english?
I am using the latest tree.hh from http://tree.phi-sci.com/download.html.
It produces the errors (please see below). How can I fix it? How can this class produce so many errors?
Thanks in advance for your suggesstions?
In file included from item_tree.h:4:0,
from Player.h:44,
from xinemediaplayer.c:26:
tree.hh:82:36: error: expected ‘,’ or ‘...’ before ‘&&’ token
tree(tree<T, tree_node_allocator>&&); // move constructor^M
^
tree.hh:82:38: error: invalid constructor; you probably meant ‘tree<T, tree_node_allocator> (const tree<T, tree_node_allocator>&)’
tree(tree<T, tree_node_allocator>&&); // move constructor^M
^
tree.hh:85:70: error: expected ‘,’ or ‘...’ before ‘&&’ token
tree<T,tree_node_allocator>& operator=(tree<T, tree_node_allocator>&&); // move assignment^M
^
tree.hh:503:64: error: expected ‘,’ or ‘...’ before ‘&&’ token
tree<T, tree_node_allocator>::tree(tree<T, tree_node_allocator>&& x) ^M
^
tree.hh:503:1: error: prototype for ‘tree<T, tree_node_allocator>::tree(tree<T, tree_node_allocator>)’ does not match any in class ‘tree<T, tree_node_allocator>’
tree<T, tree_node_allocator>::tree(tree<T, tree_node_allocator>&& x) ^M
^
tree.hh:81:3: error: candidates are: tree<T, tree_node_allocator>::tree(const tree<T, tree_node_allocator>&)
tree(const tree<T, tree_node_allocator>&); // copy constructor^M
^
tree.hh:80:3: error: tree<T, tree_node_allocator>::tree(const tree<T, tree_node_allocator>::iterator_base&)
tree(const iterator_base&);^M
^
tree.hh:496:1: error: tree<T, tree_node_allocator>::tree(const T&)
tree<T, tree_node_allocator>::tree(const T& x) ^M
^
tree.hh:490:1: error: tree<T, tree_node_allocator>::tree()
tree<T, tree_node_allocator>::tree() ^M
^
tree.hh:562:98: error: expected ‘,’ or ‘...’ before ‘&&’ token
tree<T,tree_node_allocator>& tree<T, tree_node_allocator>::operator=(tree<T, tree_node_allocator>&& x)^M
^
tree.hh: In member function ‘tree<T, tree_node_allocator>& tree<T, tree_node_allocator>::operator=(tree<T, tree_node_allocator>)’:...
an example of tree.hh:
64 template <class T, class tree_node_allocator = std::allocator<tree_node_<T> > >
65 class tree {
66 protected:
67 typedef tree_node_<T> tree_node;
68 public:
69 /// Value of the data stored at a node.
70 typedef T value_type;
71
72 class iterator_base;
73 class pre_order_iterator;
74 class post_order_iterator;
75 class sibling_iterator;
76 class leaf_iterator;
77
78 tree(); // empty constructor
79 tree(const T&); // constructor setting given element as head
80 tree(const iterator_base&);
81 tree(const tree<T, tree_node_allocator>&); // copy constructor
82 tree(tree<T, tree_node_allocator>&&); // move constructor
83 ~tree();
84 tree<T,tree_node_allocator>& operator=(const tree<T, tree_node_allocator>&); // copy assignment
85 tree<T,tree_node_allocator>& operator=(tree<T, tree_node_allocator>&&); // move assignment
86
87 /// Base class for iterators, only pointers stored, no traversal logic.
88 #ifdef __SGI_STL_PORT
89 class iterator_base : public stlport::bidirectional_iterator<T, ptrdiff_t> {
90 #else
The Makefile is:
1 PLUGIN = xinemediaplayer
2 OBJS = $(PLUGIN).o Control.o Player.o Reel.o SpuDecode.o Utils.o \
3 curl_download.o imagetools.o \
4 item_tree.o m3u_parser.o pls_parser.o timecounter.o \
5 xineOsd.o xineOsdInfoMenu.o xineOsdFunction.o Playlist.o
6 VDRDIR = ../../..
7 LIBDIR = ../../lib
8 TMPDIR = /tmp
9 -include $(VDRDIR)/Make.config
10 ARCHIVE = $(PLUGIN)-$(VERSION)
11 PACKAGE = vdr-$(ARCHIVE)
12 OBJS += cddb.o cdtext.o cdrom.o
13 OBJS += XineLib.o GstreamerLib.o gstTools.o ExternalLib.o
14 LIBS += -lxine `pkg-config --libs gstreamer-0.10` `pkg-config --libs gstreamer-interfaces-0.10`
15 INCLUDES += `pkg-config --cflags gstreamer-0.10` `pkg-config --cflags gstreamer-interfaces-0.10`
16 -include $(VDRDIR)/Make.common
17 INCLUDES +=
18 INCLUDES +=`taglib-config --cflags`
19 LDFLAGS +=`taglib-config --libs`
20 LIBS += `curl-config --libs` -lcdio -lcddb
21
22 DEFINES += -DPLAYER_VERSION=\"$(PLAYER_VERSION)\" -D__LINUX__ -D__STL_CONFIG_H
23
24 target-for-compatibility-with-vanilla-vdr:
25 $(LIBDIR)/$#.$(APIVERSION)
Make.config:
1 REELVDR=1
2 DEBUG = 1
3 VDRVER ?= 2.1
4 CCACHE := $(shell which ccache)
5 MAKE += -j3
6 LSB_RELEASE := $(shell lsb_release -sr)
7 MACHINE ?= -m32 -march=pentium3 -mmmx -msse -mfpmath=sse
8 CC = $(CCACHE) $(DISTCC) $(CROSS)gcc
9 CFLAGS = -O2 -g -pg $(MACHINE)
10 CXX = $(CCACHE) $(DISTCC) $(CROSS)g++
11 CXXFLAGS = -g3 -funroll-loops -fomit-frame-pointer $(MACHINE) -Wall -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -D_ LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
12 STRIP = $(CROSS)strip
13 export CC CXX CFLAGS CXXFLAGS
14 CC := $(CC)-4.8
15 CXX := $(CXX)-4.8
16 DEFINES += -DDVBAPI_V5
17 DEFINES += -DNEW_FFMPEG
18 USEMYSQL = 1
19 DEVICE_ATTRIBUTES = 1
20 DVBDIR := /usr/src/linux-headers-3.13.0-66-generic/include/config/dvb
21 VDRVER := 2.1
&& is C++ 11 feature.
You should use --std=c++11 or --std=gnu++11 command line option when making g++ call.