davidrmiller / neural2d

Neural net optimized for 2D image data
MIT License
142 stars 69 forks source link

Cannot make project on Mac OS X #11

Closed ibalashov closed 9 years ago

ibalashov commented 9 years ago

Make project on OS X gives the error below. Any ideas if this could be fixed?

OS X 10.9.5 gcc: stable 4.9.2 (bottled)

neural2d$ make
g++ -std=c++11 -pthread -g -O2 -Wall -Wextra -pedantic -Wno-missing-field-initializers -c neural2d-core.cpp -o neural2d-core.o
neural2d-core.cpp:115:46: error: use of undeclared identifier 'tanh'
float transferFunctionTanh(float x) { return tanh(x); }
                                             ^
neural2d-core.cpp:116:62: error: use of undeclared identifier 'tanh'
float transferFunctionDerivativeTanh(float x) { return 1.0 - tanh(x) * tanh(x); }
                                                             ^
neural2d-core.cpp:116:72: error: use of undeclared identifier 'tanh'
float transferFunctionDerivativeTanh(float x) { return 1.0 - tanh(x) * tanh(x); }
                                                                       ^
neural2d-core.cpp:119:63: error: use of undeclared identifier 'exp'
float transferFunctionLogistic(float x) { return 1.0 / (1.0 + exp(-x)); }
                                                              ^
neural2d-core.cpp:120:60: error: use of undeclared identifier 'exp'
float transferFunctionDerivativeLogistic(float x) { return exp(-x) / pow((exp(-x) + 1.0), 2.0); }
                                                           ^
neural2d-core.cpp:120:75: error: use of undeclared identifier 'exp'
float transferFunctionDerivativeLogistic(float x) { return exp(-x) / pow((exp(-x) + 1.0), 2.0); }
                                                                          ^
neural2d-core.cpp:136:50: error: use of undeclared identifier 'exp'
float transferFunctionGaussian(float x) { return exp(-((x * x) / 2.0)); }
                                                 ^
neural2d-core.cpp:137:65: error: use of undeclared identifier 'exp'
float transferFunctionDerivativeGaussian(float x) { return -x * exp(-(x * x) / 2.0); }
                                                                ^
neural2d-core.cpp:1134:79: error: use of undeclared identifier 'sqrt'
                    connections.back().weight = ((randomFloat() * 2) - 1.0) / sqrt(maxNumSourceNeurons);
                                                                              ^
9 errors generated.
make: *** [neural2d-core.o] Error 1

$ brew info gcc
gcc: stable 4.9.2 (bottled)
davidrmiller commented 9 years ago

Thanks for reporting this. It looks like we need to add "#include <cmath>" to the top of neural2d-core.cpp. (I do not have a Mac on which to test this. Please leave a comment here or open a new issue if that fails to fix the problem.)

ibalashov commented 9 years ago

@davidrmiller Thanks! Adding the include got me past this error. However, now I'm getting:

neural2d$ make
g++ -std=c++11 -pthread -g -O2 -Wall -Wextra -pedantic -Wno-missing-field-initializers -c neural2d-core.cpp -o neural2d-core.o
g++ -std=c++11 -pthread -g -O2 -Wall -Wextra -pedantic -Wno-missing-field-initializers -c webserver.cpp -o webserver.o
webserver.cpp:229:12: error: invalid operands to binary expression ('int' and '__bind<int &, sockaddr *, unsigned long>')
    if (-1 == bind(socketFd, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) {
        ~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [webserver.o] Error 1
jeandudey commented 9 years ago

The cause of this error is that the code uses "using namespace std;" to solve this you have to change bind to ::bind.

ibalashov commented 9 years ago

@jeandudey Thanks! It solved the problem, except the warning which I guess might be ignored:

clang: warning: argument unused during compilation: '-pthread'
jeandudey commented 9 years ago

:+1:

davidrmiller commented 9 years ago

I checked in 3f5372a6420fb38b3dea7090533d60d11afc72d8 to address the issue with the math and ::bind(). Thanks @jeandudey and @ibalashov for the contributions and testing.