NuPIC Core Linker Error

Hello all.

I’ve just compiled NuPIC core and everything went swell, or so I thought. I’m using the core library as a standalone static library in a C++ project in Eclipse (Neon) CDT, NuPIC 0.6.4.dev0, and I’ve come across an odd problem. When I compile, running
Network net();
and then returning, there are no problems. More specifically, I run this, then check if NuPIC is initialized. But I find that NuPIC is not initialized. What’s more, is that when I replace the above with:
Network net;
I get a whole slew of linker errors with reference to python libraries. For example, "undefined reference to PyInt_FromLong" or "undefined reference to PyObject_Call". I’m currently including from nupic.core/build/release/include and I’m using the library path nupic.core/build/release/lib/ with libraries nupic_core (libnupic_core.a), gtest (libgtest.a) and npymath (libnpymath.a). I started with nupic_core but added the others in an attempt to fix this issue.

The C++ source includes iostream, nupic/engine/Network.hpp, nupic/engine/NuPIC.hpp, nupic/engine/Region.hpp, nupic/ntypes/Dimensions.hpp, and nupic/utils/Log.hpp. It uses namespace std and nupic. Complete source code:
/*
* main.cpp
*
* Date: Jun 15, 2017
* Author: Sam Gallagher
*
* @brief
* @description
* TODO:
*/

#include <iostream>
#include "nupic/engine/Network.hpp"
#include "nupic/engine/NuPIC.hpp"
#include "nupic/engine/Region.hpp"
#include "nupic/ntypes/Dimensions.hpp"
#include "nupic/utils/Log.hpp"


using namespace std;
using namespace nupic;

int main() /* No input args */
{
/* Create a new HTM network */
Network net;

//Region *l1 = net.addRegion("level1","TestNode","");

/* Creating a network should initialize Nupic	 */
if(NuPIC::isInitialized())
	cout << "NuPIC initialized correctly!\n";
else
	cout << "ERROR: NuPIC did not initialize correctly.\n";

/*
if(NuPIC::isInitialized())
	cout << "NuPIC did not shutdown correctly.\n";
else
	cout << "NuPIC shutdown correctly!\n";
*/
return 0;
}

Compile command:
g++ -I/home/sam/Documents/Devel/HTM/nupic.core/build/release/include -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/main.d" -MT"src/main.o" -o “src/main.o” “…/src/main.cpp”

Linker command:
g++ -L/home/sam/Documents/Devel/HTM/nupic.core/build/release/lib/ -o “walking-nupic” ./src/main.o -lnupic_core -lgtest -lnpymath

A cropping from the errors:
/tmp/ccb94oSf.ltrans5.ltrans.o: In function nupic::PyRegion::NTA_initPython()': <artificial>:(.text+0x35): undefined reference toPy_IsInitialized’

/tmp/ccb94oSf.ltrans5.ltrans.o: In function `nupic::PyRegion::NTA_createPyNode(char const*, void*, void*, void**, char const*)’:

:(.text+0x257c): undefined reference to `PyFloat_FromString’

:(.text+0x26e9): undefined reference to `PyLong_FromUnsignedLongLong’

/tmp/ccb94oSf.ltrans5.ltrans.o: In function `nupic::PyRegion::NTA_finalizePython()’:

:(.text+0x21): undefined reference to `Py_Finalize’

Clearly there’s a problem linking to some Python library or some definitions are missing or something. The closest thing I could find was nupic.core’s py_support classes.

Other things to note:
When running ./unit_tests in release/bin, 25 tests fail. Results:

[----------] Global test environment tear-down
[==========] 319 tests from 45 test cases ran. (3076 ms total)
[  PASSED  ] 294 tests.
[  FAILED  ] 25 tests, listed below:
[  FAILED  ] RandomTest.CapnpSerialization
[  FAILED  ] PathTest.exists
[  FAILED  ] PathTest.getParent
[  FAILED  ] PathTest.getFilename
[  FAILED  ] PathTest.getBasename
[  FAILED  ] PathTest.getExtension
[  FAILED  ] PathTest.normalize
[  FAILED  ] PathTest.makeAbsolute
[  FAILED  ] PathTest.split
[  FAILED  ] PathTest.join
[  FAILED  ] PathTest.remove
[  FAILED  ] PathTest.rename
[  FAILED  ] PathTest.copy
[  FAILED  ] PathTest.copyInTemp
[  FAILED  ] PathTest.isRootDir
[  FAILED  ] PathTest.isAbsolute
[  FAILED  ] PathTest.getExecutablePath
[  FAILED  ] DirectoryTest.Existence
[  FAILED  ] DirectoryTest.setCWD
[  FAILED  ] DirectoryTest.RemoveTreeAndCreate
[  FAILED  ] DirectoryTest.CopyTree
[  FAILED  ] DirectoryTest.Iterator
[  FAILED  ] ConnectionsTest.testWriteRead
[  FAILED  ] SpatialPoolerTest.testSaveLoad
[  FAILED  ] SpatialPoolerTest.testWriteRead

I’m running Linux Mint 18 64-bit version 3.0.7, linux kernel 4.40-78-generic. Any help is greatly appreciated!
Sam

Sam, I would really like to see the console output from your nupic.core installation. It would be worth it to uninstall and install again. Save the console output in a gist or something. Also, can you say what exact commit sha you are building from?

commit c4f74e0ff018dce9c76c4da6e0958071f392dee1
Author: Marcus Lewis mrcslws@gmail.com
Date: Fri Jun 2 06:01:38 2017 -0700

Continue work on 0.6.4.dev0

diff --git a/VERSION b/VERSION
index 844f6a9…b78fcca 100644
— a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.6.3
+0.6.4.dev0

Sure, I’ll get to that right now. Will get back to you.

Sam

I reinstalled, first running “make” and then “sudo make install” from nupic.core/build/scripts/.
Gist:

:thinking: Looks like it installed properly. Not sure what is wrong. You might also try installing from tip of master.

@vkruglikov @scott @mrcslws Any clues I’m missing?

It seems there can be issues with CMake and Python as I’m looking around. I’m wondering if this could be related? I tried linking with the output of python-config --ldflags as well but nothings working yet.

Perhaps you are able to tell it where Python is at compile time but it isn’t finding it at runtime? I’m not really sure.

@sjgallagher2, I am not sure why you would get different compilation/linking results with net; vs. net();, but one thing to note is that nupic.core code has support for integrating network regions that are implemented in Python. Hence, when the linker needs to pull in some of that python-related code from the nupic_core archive, you would get unresolved references to python symbols, unless you link with the Python library. This is how the C++ tests in nupic.core resolve the python symbols: https://github.com/numenta/nupic.core/blob/7517329f54261e6ad05c6332d6e410e5c1e47122/src/CMakeLists.txt#L430

1 Like

Yes, I found the problem was the python-config --ldflags was being inserted before the "-o “myTarget” " in the call to ld. I couldn’t get eclipse to do it properly so I just added the libraries manually. The working linker was:
g++ -L/home/sam/Documents/Devel/HTM/nupic.core/build/release/lib/ -L/usr/lib/python2.7/config-x86_64-linux-gnu -L/usr/lib/ -o “walking-nupic” ./src/main.o -lnupic_core -lpython2.7 -lpthread -ldl -lutil -lm -lgtest -lnpymath

1 Like