fpco / inline-c

284 stars 50 forks source link

[inline-c-cpp] "`at` is not a namespace-name" with shared object #76

Closed stites closed 5 years ago

stites commented 5 years ago

I'm attempting to use inline-c-cpp to access functions from a C++ library, ATen, but am getting the above error about the library's namespace. The code looks like:

import qualified Language.C.Inline.Cpp as C
import qualified Language.C.Inline.Cpp.Exceptions as C

C.context C.cppCtx
C.using "namespace at"

the cabal file looks like:

executable aten
  main-is: ATenCpp.hs
  hs-source-dirs: experimental/aten-cpp
  default-language: Haskell2010
  extra-libraries: ATen
  build-depends:
        base (==4.7 || >4.7) && <5,
        inline-c-cpp

and my error is:

Build profile: -w ghc-8.6.1 -O0
In order, the following will be built (use -v for more details):
 - hasktorch-examples-0.0.1.0 (exe:aten) (file experimental/aten-cpp/ATenCpp.hs changed)
Preprocessing executable 'aten' for hasktorch-examples-0.0.1.0..
Building executable 'aten' for hasktorch-examples-0.0.1.0..
[1 of 1] Compiling Main             ( experimental/aten-cpp/ATenCpp.hs, /home/stites/git/hasktorch/dist-newstyle/build/x86_64-linux/ghc-8.6.1/hasktorch-examples-0.0.1.0/x/aten/noopt/build/aten/aten-tmp/Main.o )

/tmp/ghc28778_0/ghc_1.cpp:2:17: error:
     error: ‘at’ is not a namespace-name
     using namespace at;
                     ^~
  |
2 | using namespace at;
  |                 ^

/tmp/ghc28778_0/ghc_1.cpp:2:19: error:
     error: expected namespace-name before ‘;’ token
     using namespace at;
                       ^
  |
2 | using namespace at;
  |                   ^
`gcc' failed in phase `C Compiler'. (Exit code: 1)

Am I missing something? Should I be including the header files in my cabal file? If so, do I need to include a link to every file or is a top-level folder sufficient?

Thank you!

bitonic commented 5 years ago

@stites it looks like you're missing the import, e.g. see https://github.com/fpco/inline-c/blob/3f613e6017c2e510cd10f39a86f74be0635f168c/inline-c-cpp/test/tests.hs .