Linking failed (Undefined reference)
chaojin0310 opened this issue · 2 comments
chaojin0310 commented
Hi! I'm just starting to learn how to use cylon but I've encountered a problem. I installed cylon-0.5.0 on Ubuntu20.04 using the steps below:
cd ~
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y --no-install-recommends --no-install-suggests \
gcc g++ \
libssl-dev curl wget vim git build-essential \
python3.8-dev python3.8 maven libnuma-dev libc-dev python3-venv \
openmpi-bin libopenmpi-dev python3-pip python3-dev libutf8proc-dev libre2-dev
curl -OL https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1.tar.gz
tar -xvf cmake-3.20.1.tar.gz
rm cmake-3.20.1.tar.gz
cd cmake-3.20.1
./bootstrap
make
sudo make install
cd ~
wget https://github.com/cylondata/cylon/archive/refs/tags/0.5.0.tar.gz
tar -xvf 0.5.0.tar.gz
rm 0.5.0.tar.gz
cd cylon-0.5.0
python3 -m venv ENV
source ENV/bin/activate
mkdir $HOME/cylon_install
./build.sh -pyenv $HOME/cylon-0.5.0/ENV -bpath $HOME/cylon/build -ipath $HOME/cylon_install --cpp --release
Then I wrote a demo in order to check if it works. My demo contains just two files, CMakeLists.txt and main.cpp.
My CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 14)
project(app LANGUAGES CXX)
include_directories(../../cylon_install/include)
add_executable(${PROJECT_NAME} "main.cpp") #Add app's main starting file.
link_directories(../../cylon/build/lib)
link_directories(../../cylon/build/arrow/install/lib)
link_directories(../../cylon_install/lib)
And main.cpp is:
#include <iostream>
#include <memory>
#include <cylon/io/csv_read_config.hpp>
#include <cylon/ctx/cylon_context.hpp>
#include <cylon/table.hpp>
int main(int argc, char *argv[])
{
auto ctx = cylon::CylonContext::Init();
std::shared_ptr<cylon::Table> table1;
auto read_options = cylon::io::config::CSVReadOptions();
read_options = read_options.WithDelimiter('|');
auto status = cylon::FromCSV(ctx, "../../warehouse.dat/", table1, read_options);
std::cout << status.is_ok() << std::endl;
return 0;
}
Then I tried to compile it, but it threw a linking error:
/usr/bin/ld: CMakeFiles/app.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x37): undefined reference to `cylon::CylonContext::Init()'
/usr/bin/ld: main.cpp:(.text+0x5c): undefined reference to `cylon::io::config::CSVReadOptions::CSVReadOptions()'
/usr/bin/ld: main.cpp:(.text+0x77): undefined reference to `cylon::io::config::CSVReadOptions::WithDelimiter(char)'
/usr/bin/ld: main.cpp:(.text+0xe4): undefined reference to `cylon::FromCSV(std::shared_ptr<cylon::CylonContext> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<cylon::Table>&, cylon::io::config::CSVReadOptions const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/app.dir/build.make:97: app] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/app.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I think it's because of lack of some cylon libraries, but I cannot figure it out.
P.S., my working directory structure looks like this:
-HOME
-cylon # generated after building cylon
-build
-cylon-0.5.0 # extracted through the release-0.5.0
-cylon_install
-include
-lib
-MyRepo
-MyDemo
-CMakeLists.txt
-main.cpp
chaojin0310 commented
I forgot to link a dynamic library using target_link_libraries(XX XXX)
. A stupid mistake.
nirandaperera commented
That's a common mistake 🙂
@chaojin0310 Let us know if you need any other help.