plasmodic / ecto

ecto is a dynamically configurable Directed Acyclic processing Graph (DAG) framework.
http://ecto.willowgarage.com/
BSD 3-Clause "New" or "Revised" License
97 stars 37 forks source link

Problem with linking in ecto_tutorial: cannot open output file //ecto_tutorial/tutorial.so #276

Closed SebastianRiedel closed 9 years ago

SebastianRiedel commented 9 years ago

Following the tutorial from https://plasmodic.github.io/ecto/ecto/usage/tutorials/hello.html I have the following problem when trying to build the project:

~/software/ecto-tests/build$ make
Scanning dependencies of target tutorial_ectomodule
[ 50%] Building CXX object CMakeFiles/tutorial_ectomodule.dir/tutorial.cpp.o
[100%] Building CXX object CMakeFiles/tutorial_ectomodule.dir/hello.cpp.o
Linking CXX shared library //ecto_tutorial/tutorial.so
/usr/bin/ld: cannot open output file //ecto_tutorial/tutorial.so: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [//ecto_tutorial/tutorial.so] Error 1
make[1]: *** [CMakeFiles/tutorial_ectomodule.dir/all] Error 2

What now follows is the complete build process listing, the used CMakeLists.txt and the resulting files in the build-folder cmake was executed in.

My complete build process listing:

~/software/ecto-tests$ tree
.
├── CMakeLists.txt
├── hello.cpp
├── hello.py
└── tutorial.cpp

0 directories, 4 files
~/software/ecto-tests$ mkdir build
~/software/ecto-tests$ cd build/
~/software/ecto-tests/build$ cmake ../
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found Git: /usr/bin/git (found version "1.9.1") 
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Boost version: 1.55.0
-- Found the following Boost libraries:
--   python
--   thread
--   system
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found version "2.7.6") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sebastian/software/ecto-tests/build
~/software/ecto-tests/build$ make
Scanning dependencies of target tutorial_ectomodule
[ 50%] Building CXX object CMakeFiles/tutorial_ectomodule.dir/tutorial.cpp.o
[100%] Building CXX object CMakeFiles/tutorial_ectomodule.dir/hello.cpp.o
Linking CXX shared library //ecto_tutorial/tutorial.so
/usr/bin/ld: cannot open output file //ecto_tutorial/tutorial.so: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [//ecto_tutorial/tutorial.so] Error 1
make[1]: *** [CMakeFiles/tutorial_ectomodule.dir/all] Error 2
make: *** [all] Error 2

Used CMakeLists.txt:

~/software/ecto-tests$ cat CMakeLists.txt 
# This is standard CMake, you need that line
cmake_minimum_required(VERSION 2.8)
# This just defines the name of that project from CMake
project(hello_ecto)

# You need ecto, so find it first: that will give you access to macros
find_package(ecto REQUIRED)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# This is all you need to know: it will create an ecto module named tutorial
# and it will be built in the ${where_your_Python_lib_are_bult}/ecto_tutorial folder.
# If you add the ``INSTALL`` flag, it will also install it when you do ``make install`
ectomodule(tutorial DESTINATION ./ecto_tutorial INSTALL
    # You need a file defining the module (cf. below)
    tutorial.cpp
    # You need a file defining some content for module (cf. below)
    hello.cpp
)

Created files in build directory (no *.so file at all):

~/software/ecto-tests/build$ tree
.
├── CMakeCache.txt
├── CMakeFiles
│   ├── 2.8.12.2
│   │   ├── CMakeCCompiler.cmake
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeSystem.cmake
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   └── CMakeCCompilerId.c
│   │   └── CompilerIdCXX
│   │       ├── a.out
│   │       └── CMakeCXXCompilerId.cpp
│   ├── cmake.check_cache
│   ├── CMakeDirectoryInformation.cmake
│   ├── CMakeError.log
│   ├── CMakeOutput.log
│   ├── CMakeRuleHashes.txt
│   ├── CMakeTmp
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── Progress
│   │   ├── 1
│   │   ├── 2
│   │   └── count.txt
│   ├── progress.marks
│   ├── sphinx-doc.dir
│   │   ├── build.make
│   │   ├── cmake_clean.cmake
│   │   ├── DependInfo.cmake
│   │   └── progress.make
│   ├── TargetDirectories.txt
│   └── tutorial_ectomodule.dir
│       ├── build.make
│       ├── cmake_clean.cmake
│       ├── CXX.includecache
│       ├── DependInfo.cmake
│       ├── depend.internal
│       ├── depend.make
│       ├── flags.make
│       ├── hello.cpp.o
│       ├── link.txt
│       ├── progress.make
│       └── tutorial.cpp.o
├── cmake_install.cmake
└── Makefile

The tutorial.cpp, hello.cpp and hello.py are exactly as in the tutorial. Seems to be the same error as in https://groups.google.com/a/plasmodic.org/forum/#!topic/ecto-dev/H_Qo4BLW40s

System information: Ubuntu 14.04 x64

SebastianRiedel commented 9 years ago

I found out that the following command sequence works:

mkdir build
cd build
cmake ../
mkdir ecto_tutorial
vim CMakeFiles/tutorial_ectomodule.dir/link.txt (editing link.txt, see remarks below)
make

The original link.txt generated using cmake looks like:

/usr/bin/c++  -fPIC  -shared-libgcc   -shared -Wl,-soname,tutorial.so -o //ecto_tutorial/tutorial.so CMakeFiles/tutorial_ectomodule.dir/tutorial.cpp.o CMakeFiles/tutorial_ectomodule.dir/hello.cpp.o -lboost_python -lboost_thread -lboost_system -lpthread -lpython2.7 /home/sebastian/software/ecto/build/devel/lib/libecto.so -lpython2.7 /home/sebastian/software/ecto/build/devel/lib/libecto.so -Wl,-rpath,/home/sebastian/software/ecto/build/devel/lib:

in which the option -o //ecto_tutorial/tutorial.so has to be changed to -o ./ecto_tutorial/tutorial.so to make the library generation work. Also, I need to create the directory manually using mkdir ecto_tutorial (see command sequence above).

I hope this helps in finding the error.

SebastianRiedel commented 9 years ago

@vrabaud the issue described here results from the commit 2e020c478e52903efbd71c343f9a812550632b07 where cmake checks for ROS_GROOVY etc have been removed. That leads to the hard requirement that in ectoMacros.cmake catkin specific cmake variables have to be set (e.g. CATKIN_DEVEL_PREFIX). If they are not set they result in empty substitution and therefore paths like the above linking option -o //ecto_tutorial/tutorial.so.

The issue is resolved as soon as one adds find_package(catkin REQUIRED) to the ecto_tutorial CMakeLists.txt. That could be updated in the tutorials in https://plasmodic.github.io/ecto/ecto/usage/tutorials/hello.html and https://plasmodic.github.io/ecto/ecto/usage/client_usage.html

YantianZha commented 8 years ago

I followed this tutorial: http://plasmodic.github.io/ecto/ecto/usage/tutorials/hello.html. After adding "find_package(catkin REQUIRED) ", I can cmake my ecto_tutorial folder. Things in ecto_tutorial are "build/ CMakeLists.txt ecto_tutorial/ Hello.cpp hello.py* init.py tutorial.cpp".

Then I cd build, mkdir ecto_tutorial (~/ecto_tutorial/build$ mkdir ecto_tutorial), then things are: catkin/ CATKIN_IGNORE CMakeFiles/ CTestTestfile.cmake ecto_tutorial/ Makefile catkin_generated/ CMakeCache.txt cmake_install.cmake devel/ gtest/ test_results/

Then export PYTHONPATH=~/ecto_tutorial/build:$PYTHONPATH

Then I can run "touch ./build/ecto_tutorial/init.py". Everything is fine now.

However, if I run "chmod 755 hello.py && ./hello.py" (~/ecto_tutorial$ chmod 755 hello.py && ./hello.py), I got error: ImportError: No module named tutorial

I don't know why this can happen?

And in my build folder after "vim CMakeFiles/tutorial_ectomodule.dir/link.txt", the line is different from the sitution of @SebastianRiedel in MY CASE: -o devel/lib/python2.7/ecto_tutorial/tutorial.so

Here is my folder: https://drive.google.com/folderview?id=0B6lGtF9IuZWCd21ONEljQXBLMFE&usp=sharing

Thanks very much!