Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name frontend #249

Closed
huyn opened this issue Oct 31, 2017 · 18 comments
Closed

cannot import name frontend #249

huyn opened this issue Oct 31, 2017 · 18 comments

Comments

@huyn
Copy link

huyn commented Oct 31, 2017

When I was compiling th++ after installing folly and fbthrift, I encountered an error

[  5%] Generating thpp/if/gen-cpp2/Tensor_data.h, thpp/if/gen-cpp2/Tensor_types.h, thpp/if/gen-cpp2/Tensor_types.tcc, thpp/if/gen-cpp2/Tensor_constants.h, thpp/if/gen-cpp2/Tensor_data.cpp, thpp/if/gen-cpp2/Tensor_types.cpp, thpp/if/gen-cpp2/Tensor_constants.cpp
/usr/bin/python: cannot import name frontend
CMakeFiles/thpp.dir/build.make:61: recipe for target 'thpp/if/gen-cpp2/Tensor_data.h' failed
make[2]: *** [thpp/if/gen-cpp2/Tensor_data.h] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/thpp.dir/all' failed
make[1]: *** [CMakeFiles/thpp.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I checked frontend.so under fbthrift, but I could find it.
My question is How should I do to generate frontend.so?
Many thanks in advance.

@TaoTaoFu
Copy link

TaoTaoFu commented Nov 7, 2017

hi, do you solve it ? I meet the same problem :(

@huyn
Copy link
Author

huyn commented Nov 10, 2017

@TaoTaoFu not yet.
branch v1.0 on ubuntu 14.04 seems work.

@TaoTaoFu
Copy link

thanks, I will try it. @huyn

@lwjyqjykn
Copy link

i also came up this problem, how do you slove it@TaoTaoFu

@fengyang0317
Copy link

We can manually compile the frontend.so file. The following is the command I used.

g++ -I /usr/include/python2.7 -I /home/yfeng23/utils/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto

@ZYX-MLer
Copy link

ZYX-MLer commented Dec 13, 2017

@fengyang0317 I compile frontend.so as your advise and get frontend.so in /fbthrift/thrift/compiler/py/frontend.so but i still get the error:
/usr/bin/python: cannot import name frontend

when i copy frontend.so to python2.7/dist-packages I can import frontend in python but still get that error when run ./build.sh

how do you slove it?

@siahewei
Copy link

i have faced same problem on ubuntu16.04, and i solve it from related information. frontend.so can copile by script "g++ -I /usr/include/python2.7 -I ./fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto" . then faced another problem "relocation R_X86_64_32 against", fix CMakefile.txt add "set(CMAKE_CXX_FLAGS "-fPIC")
set(CMAKE_C_FLAGS "-fPIC")", will be successed. good luck for you.

@Jayhello
Copy link

I just want to say FUCK! waste me lots of time

@Jayhello
Copy link

as @siahewei method I solve this, remember to make install After reinstall.

@SunnyCat2013
Copy link

As I said in facebookarchive/thpp#51 (comment) , you should copy frontend to somewhere under directory thrift_compiler.

@raffra
Copy link

raffra commented Jan 21, 2018

@siahewei
Hi! I'm trying to replicate your fix recompiling fbthrift with CMAKE_CXX_FLAGS and CMAKE_C_FLAGS set to -fPIC but without success. Can you describe better your procedure?

This is what I'm doing:
-- I've added the two "set command" in the libs_only section of the fbthrift CMakeList.txt

    set(CMAKE_CXX_FLAGS "-fPIC")
    set(CMAKE_C_FLAGS "-fPIC")

-- I'm enabling libs_only flag with cmake-gui for fbthrift
-- I created another package with checkinstall called fbthrift_libs
-- I installed it with sudo dpkg --install --force-all
-- I'm running the command

   g++ -I /usr/include/python2.7 -I /home/francesco/openface/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto

in this path
/home/francesco/openface/fbthrift/thrift/compiler/py

I remember that I've seen the "compile only" in another package, maybe thift itself, do you think I've to recompile it again even adding these flags?

@k22jung
Copy link

k22jung commented Feb 20, 2018

@raffra which CMakefile.txt did you edit? Make sure it's the Makefile in /fbthrift/thrift/compiler, because there are multiple CMakefiles and after placing the flags in that file it worked.

@engahmed1190
Copy link

engahmed1190 commented Feb 22, 2018

i have run this command under /fbthrift/thrift/compiler/py
g++ -I /usr/include/python2.7 -I /tmp/fblualib-build.FSDy82/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto

and added at the beginning of CMakefile.txt


# Set the compiler directory
set(COMPILER_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Override default install path for `make install` step
set(CMAKE_INSTALL_PREFIX ${THRIFT_HOME})
set(CMAKE_CXX_FLAGS "-fPIC")
set(CMAKE_C_FLAGS "-fPIC")
# Compile Flex and Bison files and tie their dependencies 

still the same error

`

/usr/bin/ld: //usr/local/lib/libcompiler_base.a(common.cc.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

`

@gbolin
Copy link

gbolin commented Feb 24, 2018

@engahmed1190 , I solved your problem, here is my operation.
1.modify CMakefile.txt
2.rebuild/reinstall fbthrift(must step)
3.run you command under /fbthrift/thrift/compiler/py

g++ -I /usr/include/python2.7 -I /tmp/fblualib-build.FSDy82/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto

after this, you get your frontend.so successfully.

@ilovin
Copy link

ilovin commented May 8, 2018

thx @githubgs

  1. modify which CMakeList? under the 'fbthrift'
    add two line
set(CMAKE_CXX_FLAGS "-fPIC")
set(CMAKE_C_FLAGS "-fPIC")
  1. rebuild/reinstall
  2. for python3
g++ -I /usr/include/python3.5 -I /tmp/fblualib-build.***/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python-py35 -lpython3.5m -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto

ldconfig -p to find the python version

@adam-dziedzic
Copy link

adam-dziedzic commented Jun 27, 2018

what @siahewei wrote was very helpful!

I also compiled the python files afterwards, so the whole thing is:


dir=`pwd`
git clone https://github.com/facebook/fbthrift
cd fbthrift
# echo "set(CMAKE_CXX_FLAGS "-fPIC")" >> CMakeLists.txt 
# echo "set(CMAKE_C_FLAGS "-fPIC")" >> CMakeLists.txt
# https://stackoverflow.com/questions/9533679/how-to-insert-a-text-at-the-beginning-of-a-file
# https://github.com/facebook/fbthrift/issues/249
sed -i '6s/^/set(CMAKE_CXX_FLAGS "-fPIC")\n/' CMakeLists.txt
sed -i '7s/^/set(CMAKE_C_FLAGS "-fPIC")\n/' CMakeLists.txt

cd build
cmake .. # Add -DOPENSSL_ROOT_DIR for macOS. Usually in /usr/local/ssl
# make # or make -j $(nproc), or make install.
make -j $(nproc)
sudo make install
sudo ldconfig
cd ${dir}

# more problems with thrift
# in ~/fbthrift/thrift/compiler/py$
init_dir=`pwd`
cd fbthrift/thrift/compiler/py
sudo g++ -I /usr/include/python2.7 -I /home/${USER}/fbthrift -std=c++14 -fpic -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto
cd ${init_dir}

init_dir=`pwd`
# it has to be python 2.7
mkdir tmp
cp -a fbthrift/thrift/compiler/py tmp/
cd tmp/py
sudo python setup.py install
cd ${init_dir}
 

@sani1486
Copy link

sudo g++ -I /usr/include/python2.7 -I /home/sani/fbthrift/ -std=c++14 -fPIC -shared -o frontend.so compiler.cc -lboost_python -lpython2.7 -L/build/lib -Wl,--start-group -lcompiler_base -lcompiler_base -lcompiler_ast -lboost_system -lboost_filesystem -lssl -lcrypto -Wl,--end-group

I cant figure out what am i doing wrong here .. Please help me someone .

@avalonalex
Copy link
Contributor

Python front end is no loner needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests