SuperElastix / SimpleElastix

Multi-lingual medical image registration library
http://simpleelastix.github.io
Apache License 2.0
509 stars 149 forks source link

Cannot install SimpleElastix on Ubuntu 20.04 for Python, R and Ruby #433

Open fluidpolyheadron opened 3 years ago

fluidpolyheadron commented 3 years ago

Good evening everyone

It is as the title says. For context, I installed all previous packages with apt-get as per the manual. I use Anaconda and have yet to go to that issue of how to connect.

My problem comes with the following error message, as in the following file: Error_Message.odt

Please help, as I have passed countless hours today and yesterday trying to fix it myself and only got worse.

Also, please let me know any additional information you might need, I am always online with the exception of 8hrs per day or when I am on meetings.

jakob1379 commented 3 years ago

What system are you on, what version of SimepleElastix, GCC, and Clang are you using?

Also check here on how to format text here

fluidpolyheadron commented 3 years ago

I am on Ubuntu 20 I am using the latest version https://github.com/SuperElastix/SimpleElastix

jakob1379 commented 3 years ago

The error message extracted from the odt-file..

[ 63%] Linking CXX executable ../../bin/sitkSystemInformationTest
/software/SimpleElastix/build/SimpleITK-build/Wrapping/Ruby/SimpleITKRUBY_wrap.cxx: In function ‘void SWIG_RubyInitializeTrackings()’:
/software/SimpleElastix/build/SimpleITK-build/Wrapping/Ruby/SimpleITKRUBY_wrap.cxx:1264:85: error: call of overloaded ‘rb_define_virtual_variable(const char [21], VALUE (&)(...), NULL)’ is ambiguous
 1264 |   rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL);
      |                                                                                     ^
In file included from /usr/include/ruby-2.7.0/ruby/ruby.h:2863,
                 from /usr/include/ruby-2.7.0/ruby.h:33,
                 from /software/SimpleElastix/build/SimpleITK-build/Wrapping/Ruby/SimpleITKRUBY_wrap.cxx:880:
/usr/include/ruby-2.7.0/ruby/backward/cxxanyargs.hpp:59:1: note: candidate: ‘void ruby::backward::cxxanyargs::rb_define_virtual_variable(const char*, VALUE (*)(...), void (*)(...))’
   59 | rb_define_virtual_variable(const char *q, type *w, void_type *e)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/ruby-2.7.0/ruby/backward/cxxanyargs.hpp:90:1: note: candidate: ‘void ruby::backward::cxxanyargs::rb_define_virtual_variable(const char*, VALUE (*)(...), void (*)(VALUE, ID, VALUE*))’
   90 | rb_define_virtual_variable(const char *q, type *w, rb_gvar_setter_t *e)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
[ 63%] Built target sitkSystemInformationTest
[ 63%] Built target SimpleITKUnitTestBase
[ 63%] Linking CXX executable ../bin/BufferImportExport
[ 63%] Built target BufferImportExport
[ 63%] Linking CXX executable ../bin/SimpleGaussianFunctional
[ 63%] Built target SimpleGaussianFunctional
[ 64%] Linking CXX executable ../bin/tfx
[ 64%] Built target tfx
[ 64%] Linking CXX executable ../bin/elx
[ 64%] Built target SimpleITKCSharpNative_CSHARP
[ 64%] Linking CXX executable ../../bin/NeighborhoodConnectedImageFilter
make[5]: *** [Wrapping/Ruby/CMakeFiles/simpleitk_RUBY.dir/build.make:410: Wrapping/Ruby/CMakeFiles/simpleitk_RUBY.dir/SimpleITKRUBY_wrap.cxx.o] Erro 1
make[4]: *** [CMakeFiles/Makefile2:4217: Wrapping/Ruby/CMakeFiles/simpleitk_RUBY.dir/all] Erro 2
make[4]: *** A aguardar por trabalhos não terminados....
Installing R package for testing and building binary version for distribution

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R é um software livre e vem sem GARANTIA ALGUMA.
Você pode redistribuí-lo sob certas circunstâncias.
Digite 'license()' ou 'licence()' para detalhes de distribuição.

R é um projeto colaborativo com muitos contribuidores.
Digite 'contributors()' para obter mais informações e
'citation()' para saber como citar o R ou pacotes do R em publicações.

Digite 'demo()' para demonstrações, 'help()' para o sistema on-line de ajuda,
ou 'help.start()' para abrir o sistema de ajuda em HTML no seu navegador.
Digite 'q()' para sair do R.

> # Modify SimpleITK.R as follows:
> #
> # remove the various delete generic methods. These are not
> # used and are created incorrectly by swig (calling something
> # that doesn't exist).
> # Ultimately I will fix swig, but the turnaround is too long.
> #
> # Generate some documentation files for the various $ methods.
> # The CRAN checks complain about missing documentation otherwise.
> #
> # Both of these steps can be accomplished largely with grep-style
> # approaches.
> #
> #
> # Call the script as follows:
> #
> # R -f processSwigCode.R --args SimpleITK.R Packaging/SimpleITK/R/SimpleITK.R Packaging/SimpleITK/man/hidden_methods.Rd
> #
> # Arguments 1) the R file generated by swig
> #           2) output file for modified R code
> #           3) output documentation file containing the $ methods
> 
> 
> writeAlias <- function(m, outfile) {
+   con <- file(outfile, open='w')
+   writeLines(c("\\docType{data}",
+                "\\name{hidden_methods}",
+                "\\alias{hidden_methods}"), con)
+ 
+   p <- gsub("^setMethod\\(\\'\\$\\', \\'(.+)\\', function.+", "\\1", m)
+   p <- paste0("\\alias{$,", p, "-method}")
+   writeLines(p, con)
+   writeLines(c("\\title{Internal page for hidden methods}",
+                "\\description{ For S4 methods that require docmentation, but clutter index }",
+                "\\keyword{internal}"), con)
+ 
+   close(con)
+ }
> 
> processSwig <- function(swigsrc, swigdest, docdest) {
+   code <- readLines(swigsrc)
+   code <- grep("^setMethod\\('delete',", code, value=TRUE, invert=TRUE)
+   writeLines(code, swigdest)
+   dollarmethods <- grep("^setMethod\\('\\$',", code, value=TRUE)
+   writeAlias(dollarmethods, docdest)
+ }
> args <- commandArgs( TRUE )
> src <- args[[1]]
> dest <- args[[2]]
> destdoc <- args[[3]]
> processSwig(src, dest, destdoc)
> q(save="no")

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R é um software livre e vem sem GARANTIA ALGUMA.
Você pode redistribuí-lo sob certas circunstâncias.
Digite 'license()' ou 'licence()' para detalhes de distribuição.

R é um projeto colaborativo com muitos contribuidores.
Digite 'contributors()' para obter mais informações e
'citation()' para saber como citar o R ou pacotes do R em publicações.

Digite 'demo()' para demonstrações, 'help()' para o sistema on-line de ajuda,
ou 'help.start()' para abrir o sistema de ajuda em HTML no seu navegador.
Digite 'q()' para sair do R.

> parseSWIGNamespaceFile <- function(nspace) {
+   ## SWIG attemtpts to generate a package namespace file, but it is
+   ## very wrong, at least for simpleITK. However it does contain a useful
+   ## list of names that we can work with.
+   ##
+   ## Everything in SimpleITK is done with S4 classes. However the user never
+   ## needs to create them by hand, everything is done by constructor functions,
+   ## $ method and delete. We thus want to export functions ending in ImageFilter,
+   ## the same names without ImageFilter, the associated $ and delete methods
+   ## then perhaps some operator stuff by hand.
+ 
+   ## parse the text file using the R parser, as the swig generated namespace is
+   ## basically like function calls
+   cde <- parse(nspace)
+   ## Turn this into lists with useful structure
+   cde <- lapply(cde, as.list)
+   fnames <- lapply(cde, "[[", 1)
+   fargs <- lapply(cde, function(X) {
+     X <- sapply(X[-1], as.character)
+     X
+   })
+   names(fargs) <- fnames
+ 
+   ## We're interested in the export list, which includes all the image filters
+   ## get all names starting with delete_ and ending in ImageFilter
+   allclasses <- grep("^delete_.+", fargs$export, value=TRUE)
+   classnames <- gsub("^delete_(.+)$", "\\1", allclasses)
+   imagefilterfunctions <- gsub("^(.+)ImageFilter$", "\\1", classnames)
+   classnamesreduced <- grep("^(.+)ImageFilter$", classnames, value=TRUE, invert=TRUE)
+   otherfilterfunctions <- gsub("^(.+)Filter$", "\\1", classnamesreduced)
+   thefunctions <- c(imagefilterfunctions, otherfilterfunctions)
+   # confirm that there is a procedural version by matching against the original export list
+   # only imagefilters have procedural versions
+   realfunction <- thefunctions %in% fargs$export
+   thefunctions <- thefunctions[realfunction]
+ 
+   ## Special functions, like ReadImage, don't have associated new_ methods
+   ## However, very difficult to filter the method names. e.g
+ 
+   return(list(filters=classnames[!duplicated(classnames)], functions=thefunctions[!duplicated(thefunctions)]))
+ }
> 
> writeSITKNamespace <- function(objlist) {
+   ll <- paste0('"', c(objlist$filters, objlist$functions), '"')
+   llh <- paste0(head(ll, -1), ",")
+   ll <- c("export(", llh, tail(ll, 1), ")")
+   return(ll)
+ }
> 
> handExports <- function() {
+   f <- c('import(methods)',
+          'importFrom("utils", "head", "tail")',
+          'useDynLib(SimpleITK)',
+          'exportClasses("_p_itk__simple__Image")',
+          'export("as.image")',
+          'export("ReadImage", "ReadTransform", "WriteImage", "WriteTransform",
+   "GaborSource", "GridSource", "GaussianSource", "PhysicalPointSource",
+   "GetPixelIDValueAsString", "GetPixelIDValueFromString", "Show")',
+          'export("ImageSeriesReader_GetGDCMSeriesFileNames","ImageSeriesReader_GetGDCMSeriesIDs")',
+          'exportMethods("$", "print", "show", "as.array")')
+ 
+   f
+ }
> 
> manualexclusions <- c("DoubleDoubleMap", "RCommand", "VectorBool", "VectorDouble", "VectorFloat",
+                       "VectorInt16", "VectorInt32", "VectorInt64",
+                       "VectorInt8", "VectorOfImage", "VectorString",
+                       "VectorUInt16", "VectorUInt32", "VectorUInt64",
+                       "VectorUInt8", "VectorUIntList", "ImageFilter_0",
+                       "ImageFilter_1", "ImageFilter_2", "ImageFilter_3",
+                       "ImageFilter_4", "ImageFilter_5", "ImageFilter_6",
+                       "ImageFilter_7", "ImageFilter_8", "ImageFilter_9",
+                       "ProcessObject", "ImageReaderBase")
> 
> 
> newNAMESPACE <- function(oldnamespace, targetnamespace) {
+   byhand <- handExports()
+   swigstuff <- parseSWIGNamespaceFile(oldnamespace)
+   swigstuff$filters <- setdiff(swigstuff$filters, manualexclusions)
+   auto <- writeSITKNamespace(swigstuff)
+   writeLines(c(byhand, auto), targetnamespace)
+ }
> 
> args <- commandArgs( TRUE )
> src <- args[[1]]
> dest <- args[[2]]
> 
> newNAMESPACE(src, dest)
> q(save="no")
* installing *source* package ‘SimpleITK’ ...
** using staged installation
** libs
** arch - 
make[6]: aviso: jobserver indisponível: a usar -j1.  Adicionar "+" à regra-mãe make.
Dummy makefile for binary package
installing to /software/SimpleElastix/build/SimpleITK-build/Wrapping/R/R_libs/00LOCK-SimpleITK/00new/SimpleITK/libs
** R
[ 64%] Built target NeighborhoodConnectedImageFilter
** inst
** byte-compile and prepare package for lazy loading
[ 64%] Built target elx
Creating a generic function for ‘xor’ from package ‘base’ in package ‘SimpleITK’
** help
*** installing help indices
** building package indices
** installing vignettes
   ‘SimpleITK_tutorial.Rnw’ 
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* creating tarball
packaged installation of ‘SimpleITK’ as ‘SimpleITK_2.0.0-9910_R_x86_64-pc-linux-gnu.tar.gz’
* DONE (SimpleITK)
[ 64%] Built target SimpleITK_R
make[3]: *** [Makefile:163: all] Erro 2
make[2]: *** [CMakeFiles/SimpleITK.dir/build.make:119: SimpleITK-prefix/src/SimpleITK-stamp/SimpleITK-build] Erro 2
make[1]: *** [CMakeFiles/Makefile2:216: CMakeFiles/SimpleITK.dir/all] Erro 2
make: *** [Makefile:84: all] Erro 2
fluidpolyheadron commented 3 years ago

GCC version: 9.3.0

For clang, I try clang --version but it does not have the command. However, if I try whereis clang it is in /usr/lib/clang /usr/include/clang

alinafdima commented 3 years ago

I had the same issue. I replaced the faulty line in the build folder (/software/SimpleElastix/build/SimpleITK-build/Wrapping/Ruby/SimpleITKRUBY_wrap.cxx:1264) with

rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", (rb_gvar_getter_t *)swig_ruby_trackings_count, (rb_gvar_setter_t *)NULL);

as suggested here, then recompiled make -j4.

fluidpolyheadron commented 3 years ago

I will try that this week to come, I will report here how it went.