开发者

Undefined symbols when linking with g++? How do I solve this?

开发者 https://www.devze.com 2023-02-21 03:03 出处:网络
my make file: all: hPif clean hPif : src/main.o src/fann_utils.o src/hashes.o src/Config.o g开发者_运维技巧++ src/Config.o src/main.o src/fann_utils.o src/hashes.o-lfann -L/usr/local/lib -o hPif

my make file:

all: hPif clean

hPif : src/main.o src/fann_utils.o src/hashes.o src/Config.o
    g开发者_运维技巧++ src/Config.o src/main.o src/fann_utils.o src/hashes.o  -lfann -L/usr/local/lib -o hPif

Config.o : src/Config.cpp src/Config.h
    g++ -c src/Config.cpp

hashes.o : src/hashes.cpp src/hashes.h
    g++ -c src/hashes.cpp

fann_utils.o: src/fann_utils.cpp fann_utils.h src/Config.h src/hashes.h
    g++ -c src/fann_utils.cpp 

main.o: src/main.cpp src/Config.h src/main.h src/hashes.h
    g++ -c src/main.cpp

clean: 
    rm -rf src/*o
    rm -rf *o

the error I get, upon make:

g++ src/Config.o src/main.o src/fann_utils.o src/hashes.o  -lfann -L/usr/local/lib -o hPif
Undefined symbols:
  "Config::NO_FILE_TRAIN", referenced from:
      _main in main.o
      _main in main.o
  "Config::LEARNING_RATE", referenced from:
      display_help()     in main.o
      train_network_no_file()     in main.o
      train_network()     in main.o
      _main in main.o
.
.
.

detail on code layout here: C++: I have this config class that I want to use between all my CPP files, how do I initialize it?

EDIT:

the code having issues here: http://pastebin.com/PDmHaDaC


I refer you to the accepted answer in the other question where the static variables are properly defined:

Source (Config.cpp):

#include "Config.h"

int Config::OUTPUT_TO_FILE = 0;
int Config::NEED_TO_TRAIN = 0;
int Config::NO_FILE_TRAIN = 0;
int Config::NEED_TO_TEST = 0;

Note the Config:: qualification to the variables.

Compare this to your paste bin page: http://pastebin.com/PDmHaDaC


You have just learned from your other question the theory of how to handle these static member variables. Instead of immediately trying to hook them into a large codebase, try getting them to work in a small one; write a helloWorld that uses them, just a main.cpp that defines these variables, modifies them and prints them out. Once that's working you can move the definition into Config.cpp, and once that's working you can integrate these variables into your project.

EDIT:
Here's the trouble:

int NO_FILE_TRAIN = false;

should be

int Config::NO_FILE_TRAIN = false;
0

精彩评论

暂无评论...
验证码 换一张
取 消