Weird haskell stack build exit failure: cairo requires cairo? - cairo

While experimenting with Haskell using the Stack Tool to build a gtk+ gui by enhancing the Main.hs code from the new-template as follows:
module Lib
( someFunc
) where
import Control.Monad
import Control.Monad.IO.Class
import Data.IORef
import Graphics.UI.Gtk hiding (Action, backspace)
someFunc :: IO ()
someFunc = do
void initGUI
window <- windowNew
widgetShowAll window
mainGUI
I am encountering the following weird error in which the target seems to be searching for a later version of itself:
>stack build
glib-0.13.6.0: configure
cairo-0.13.5.0: configure
Progress 2/6
-- While building package cairo-0.13.5.0 using:
/tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 configure --with-ghc=/home/gd/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc --with-ghc-pkg=/home/gd/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/pkgdb --libdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/lib --bindir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/bin --datadir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/share --libexecdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/libexec --sysconfdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/etc --docdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --htmldir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --haddockdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --dependency=Cabal=Cabal-2.2.0.1 --dependency=array=array-0.5.2.0 --dependency=base=base-4.11.1.0 --dependency=bytestring=bytestring-0.10.8.2 --dependency=gtk2hs-buildtools=gtk2hs-buildtools-0.13.4.0-DsVNfQpDbxJKtQSA2HZlGY --dependency=mtl=mtl-2.2.2 --dependency=text=text-1.2.3.1 --dependency=utf8-string=utf8-string-1.0.1.1-LRSjvSC6FZkKPp48Qszoj8
Process exited with code: ExitFailure 1
Logs have been written to: /home/gd/Projects/hgtk/.stack-work/logs/cairo-0.13.5.0.log
[1 of 2] Compiling Main ( /tmp/stack3691/cairo-0.13.5.0/Setup.hs, /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /home/gd/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/StackSetupShim.o )
Linking /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/setup ...
Configuring cairo-0.13.5.0...
setup: The pkg-config package 'cairo' version >=1.2.0 is required but it could
not be found.
Thanks in advance for any assistance.

cairo-0.13.5.0 seems to be the haskell bindings to the cairo C library (just a guess). The cairo C library's current version is 1.16 and it is "beyond 1.0" for years already. So yes, indeed, cairo requires cairo. But this is "haskell cairo bindings requires cairo C library".

Related

MATLAB — Unable to Import cv2 Library

I'm a beginner at OpenCV, and trying to run an open-source program.
http://asrl.utias.utoronto.ca/code/gpusurf/index.html
I currently have the Computer Vision Toolbox OpenCV Interface 20.1.0 installed and Computer Vision Toolbox 9.2.
I cannot run this simple open-source feature matching algorithm without encountering errors.
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
% read images
img1 = cv2.imread('[INSERT PATH #1]');
img2 = cv2.imread('[INSERT PATH #2]');
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY);
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY);
%sift
sift = cv2.xfeatures2d.SIFT_create();
keypoints_1, descriptors_1 = sift.detectAndCompute(img1,None);
keypoints_2, descriptors_2 = sift.detectAndCompute(img2,None);
len(keypoints_1), len(keypoints_2)
The following message is returned:
Error: File: Keypoints.m Line: 1 Column: 8
The import statement 'import cv2' cannot be found or cannot be imported. Imported names must end with '.*' or be
fully qualified.
However, when I remove Line 1, I instead get the following error.
Error: File: Keypoints.m Line: 2 Column: 8
The import statement 'import matplotlib.pyplot' cannot be found or cannot be imported. Imported names must end
with '.*' or be fully qualified.
Finally, following the error message only results in a sequence of further errors from the cv2 library. Any ideas?
That's because the code you've used isn't MATLAB code, it's python code.
As per the website you've linked:
From within Matlab
The parallel implementation coded in Matlab can be run by using the surf_find_keypoints() function. The output keypoints can be sorted by strength using surf_best_n_keypoints(), and plotted using surf_plot_keypoints().
Check that you've downloaded the correct files and try again.
Furthermore, the Matlab OpenCV Interface is designed to integrate C++ OpenCV code, not python. Documentations here.
Yes, it is correct that this is Python code. I would recommend checking your dependencies/libraries. The PyCharm IDE is what I personally use since it takes care of all the libraries easily.
If you do end up trying out PyCharm click on the red icon when hovering on CV2. It’ll then give you a prompt to download the library.
Edit:
Using Python some setup can be done. Using pip:
Install opencv-python
pip install opencv-python
Install opencv-contrib-python
pip install opencv-contrib-python
Unfortunately, there is some issue with the sift feature since by default it is excluded from newer free versions of OpenCV.
sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed
import cv2
Image_1 = cv2.imread("Image_1.png", cv2.IMREAD_COLOR)
Image_2 = cv2.imread("Image_2.jpg", cv2.IMREAD_COLOR)
Image_1 = cv2.cvtColor(Image_1, cv2.COLOR_BGR2GRAY)
Image_2 = cv2.cvtColor(Image_2, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT_create()
keypoints_1, descriptors_1 = sift.detectAndCompute(Image_1,None)
keypoints_2, descriptors_2 = sift.detectAndCompute(Image_2,None)
len(keypoints_1), len(keypoints_2)
The error I received:
"/Users/michael/Documents/PYTHON/Test Folder/venv/bin/python" "/Users/michael/Documents/PYTHON/Test Folder/Testing.py"
Traceback (most recent call last):
File "/Users/michael/Documents/PYTHON/Test Folder/Testing.py", line 9, in <module>
sift = cv2.SIFT_create()
AttributeError: module 'cv2.cv2' has no attribute 'SIFT_create'
Process finished with exit code 1

Rust `unresolved import` on third party library

I want to compile a simple rust program using a third party library named warp:
[package]
name = "hello-world-warp"
version = "0.1.0"
[dependencies]
warp = "0.1.18"
In src/main.rs:
use warp::{self, path, Filter};
fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run(([127, 0, 0, 1], 3030));
}
When I run cargo build I see it download warp and lots of transitive dependencies, then I get the errors:
Compiling hello-world-warp v0.1.0 (<path>) error[E0432]: unresolved import `warp`
--> src/main.rs:3:12
|
3 | use warp::{self, path, Filter};
| ^^^^ no `warp` in the root
error: cannot find macro `path!` in this scope
I've gone through various docs on modules and crates. What am I doing wrong in this simple scenario?
The example you copied uses a syntax that works in the most recent edition of Rust, but you've accidentally set your Rust to emulate an old "2015" version of the language.
You must add:
edition = "2018"
to your Cargo.toml's [package] section.
When starting new projects, always use cargo new. It will ensure the latest edition flag is set correctly.

Building Project with Handmade Library from LLVM-IR under Xcode9 will not Link properly

I want to build a maybe unusual program, goal is to get some LLVM-IR File and compile this from terminal to some type of library and import this one in an wrapper software. This should work like an plugin. Unfortunately there were some problems on the way, which some of that I already were able to solve. But now I'm banging my head to the problem which I will describe now.
For explaining I will give you all Source my prototype project contains, but first the (very basic) project setup.
+ LinkingTestProject
+- Source
+-- main.swift
+-- TestWrapper.swift
+- Build
+- LinkingTestProject.xcodeproj
Which is a very basic setup for an Xcode Project but maybe helpful later on.
So to solve my Problem I found some good looking explanations found here, where the author created some static library and the needed .swiftmodule file. But in my case there is no usable swift file to do this, I came across with some work around.
So to create the needed .o file I am using this little command on terminal:
llc -filetype=obj TestModule.ll
Assuming the .llfile was created using this command, which indeed was used for prototyping:
swiftc -emit-ir TestModule.swift -target "x86_64-apple-macosx10.09"
So now that I get the .ofile, I have to get the .a file – like explained in the link above. Therefore the command ar rcs libTestModule.a TestModule.o was used. Following the given tutorial, I have to had some swift module, so to create one I was using the following:
swiftc -emit-module <file with same interface as ir has> -module-name TestModule
Where I am using a swift file with the same class and functions fingerprint, as the file that was translated to LLVM-IR and submitted to my program. So now (theoretically) I have everything needed to import the module in my project.
The code of the project is the following:
main.swift
import Foundation
print("starting execution!")
let wrapper = TestWrapper()
wrapper.executeModule()
TestWrapper.swift
import Foundations
import TestModule
class TestWrapper {
var module: TestModuleClass
init() {
module = TestModuleClass()
}
func executeModule() {
module.execute()
}
}
Also the TestModule file contains the following:
TestModule.swift
import Foundation
public class TestModuleClass {
public init() {}
public func execute() {
print("THIS WAS PRINTED IN MODULE")
}
}
Really straight forward so far. Now I copied the generated files to Source Folder so I am getting something like this.
+ Source
+- libTestModule.a
+- TestModule.swiftmodule
+- main.swift
+- TestWrapper.swift
Then by adding the Source folder to the "Library Search Paths", "Framework Search Paths" and "Header Search Paths" – found under "Target" -> "Build Settings" (like so $(SOURCE_ROOT)/Source. Then I also added to the "Other Linker Flags" section the "-lTestModule" flag to link against my created module(ish) type of thing here.
Now Xcode checks the module and highlights absolutely no error in editor mode. So I went down the road an just hit run...
After trying to build the project I was facing this error message:
Undefined symbols for architecture x86_64:
"__T010TestModule0aB5ClassCACycfC", referenced from:
__T017Meta_Linking_Test0C7WrapperCACycfc in TestWrapper.o
"__T010TestModule0aB5ClassCMa", referenced from:
__T017Meta_Linking_Test0C7WrapperCACycfc in TestWrapper.o
l_get_field_types_TestWrapper in TestWrapper.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Since I have build the LLVM-IR file and used the right target (x86_64) I am wondering why this one was happening.
So my research phase started and by checking the files via lipo -info libTestModule.a the result is the following:
input file TestModule.a is not a fat file
Non-fat file: TestModule.a is architecture: x86_64
Digging a little bit deeper brougt me to the nmcommand which outputted me this information:
libTestModule.a(TestModule.o):
U _OBJC_CLASS_$_SwiftObject
U _OBJC_METACLASS_$_SwiftObject
0000000000000090 T __T02v315TestModuleClassC7executeyyF
0000000000000010 T __T02v315TestModuleClassCACycfC
0000000000000080 T __T02v315TestModuleClassCACycfc
0000000000000458 s __T02v315TestModuleClassCMF
0000000000000698 b __T02v315TestModuleClassCML
0000000000000040 T __T02v315TestModuleClassCMa
0000000000000270 d __T02v315TestModuleClassCMf
0000000000000248 D __T02v315TestModuleClassCMm
0000000000000408 S __T02v315TestModuleClassCMn
0000000000000280 D __T02v315TestModuleClassCN
00000000000001a0 T __T02v315TestModuleClassCfD
0000000000000190 T __T02v315TestModuleClassCfd
U __T0BoWV
U __T0S2SBp21_builtinStringLiteral_Bw17utf8CodeUnitCountBi1_7isASCIItcfC
U __T0SSN
U __T0s27_allocateUninitializedArraySayxG_BptBwlF
U __T0s5printySayypGd_SS9separatorSS10terminatortF
U __T0s5printySayypGd_SS9separatorSS10terminatortFfA0_
U __T0s5printySayypGd_SS9separatorSS10terminatortFfA1_
0000000000000240 D __T0ypML
0000000000000140 T __T0ypMa
0000000000000434 S ___swift_reflection_version
U __objc_empty_cache
U __swift_FORCE_LOAD_$_swiftCoreFoundation
0000000000000308 D __swift_FORCE_LOAD_$_swiftCoreFoundation_$_v3
U __swift_FORCE_LOAD_$_swiftCoreGraphics
0000000000000310 D __swift_FORCE_LOAD_$_swiftCoreGraphics_$_v3
U __swift_FORCE_LOAD_$_swiftDarwin
00000000000002f0 D __swift_FORCE_LOAD_$_swiftDarwin_$_v3
U __swift_FORCE_LOAD_$_swiftDispatch
0000000000000300 D __swift_FORCE_LOAD_$_swiftDispatch_$_v3
U __swift_FORCE_LOAD_$_swiftFoundation
00000000000002e0 D __swift_FORCE_LOAD_$_swiftFoundation_$_v3
U __swift_FORCE_LOAD_$_swiftIOKit
00000000000002f8 D __swift_FORCE_LOAD_$_swiftIOKit_$_v3
U __swift_FORCE_LOAD_$_swiftObjectiveC
00000000000002e8 D __swift_FORCE_LOAD_$_swiftObjectiveC_$_v3
U __swift_allocObject
U __swift_getExistentialTypeMetadata
U __swift_getInitializedObjCClass
U __swift_slowAlloc
U __swift_slowDealloc
0000000000000000 T _main
0000000000000470 s _objc_classes
U _swift_bridgeObjectRelease
U _swift_bridgeObjectRetain
U _swift_deallocClassInstance
0000000000000070 T _swift_rt_swift_allocObject
0000000000000180 T _swift_rt_swift_getExistentialTypeMetadata
0000000000000210 T _swift_rt_swift_getInitializedObjCClass
0000000000000220 T _swift_rt_swift_slowAlloc
0000000000000230 T _swift_rt_swift_slowDealloc
00000000000003a8 s l__DATA__TtC2v315TestModuleClass
0000000000000360 s l__METACLASS_DATA__TtC2v315TestModuleClass
00000000000003f0 s l___unnamed_3
0000000000000406 s l___unnamed_4
00000000000006a0 b l_field_type_vector_TestModuleClass
00000000000001c0 t l_get_field_types_TestModuleClass
0000000000000468 s l_type_metadata_table
Maybe some of you guys have some answers, for me. How can this problem be fixed? I have no Idea an couldn't find any solution out there... Oh and I have to mention I'm using Xcode9 and Swift4.0 Compiler (swiftc) if the issue can lead to this...
Thanks for your answers.

Compiling Boost.Python toy example fails: ''error: expected unqualified-id before ‘%’ token %%bp_module"

I'm trying to compile a toy example using Boost.Python. I can compile the "quickstart" example.
However when I try to compile this toy example smoke_test.cpp:
%%bp_module smoke_test
#include <boost/python.hpp>
int test() {return 42; }
BOOST_PYTHON_MODULE(smoke_test)
{
boost::python::def("test",test);
}
and smoke_test.py:
import smoke_test
smoke_test.test()
using this Jamfile:
import python ;
import testing ;
project quickstart
: requirements
<location>.
;
# Declare a Python extension called hello.
python-extension extending : smoke_test.cpp ;
I get the following error:
smoke_test.cpp:1:1: error: expected unqualified-id before ‘%’ token
%%bp_module smoke_test
^
Does anyone know whats going wrong? I assume my Jamfile is incorrect but I'm not sure how to fix it.
I'm using boos 1.63.0 and python 2.7.
I guess the %%bp_module smoke_test line was false as mentioned by #doqtor. This was probably a toy example made for ipython notebook only. Although I couldn't figure out how to use bjam and Jamfiles to compile the code, I'm still now able to compile with this minimal Makefile example using my Ubuntu 14.04 system boost version (1.54.0):
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
# compile mesh classes
TARGET = smoke_test
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Installing Pygame in PyPy via a Mac

I tried installing Pygame version 1.9.1release for PyPy on my Mac OSX Lion. I ran pypy config.py first with pypy setup.py install. I added the config to the installation process since I saw that it was trying to configure with normal python (which installs correctly, but causes import errors). Durring the installation process, there are many warnings such as:
src/overlay.c:44:5: warning: implicit declaration of function 'PyObject_Free' is invalid in C99 [-Wimplicit-function-declaration]
PyObject_Free ((PyObject*)self);
^
But it also provided me with 2 similar errors:
In file included from src/scale_mmx.c:33:
src/scale_mmx64.c:424:27: error: invalid instruction mnemonic 'movsxl'
asm __volatile__( " /* MMX code for inner loop of X bilinear filter */ "
^
<inline asm>:1:191: note: instantiated into assembly here
/* MMX code for inner loop of X bilinear filter */ movl -36(%rbp), %ecx; pxor %mm0, %mm0; 1: movsxl (%rdi), ...
^~~~~~
In file included from src/scale_mmx.c:33:
src/scale_mmx64.c:499:27: error: invalid instruction mnemonic 'movsxl'
asm __volatile__( " /* MMX code for inner loop of X bilinear filter */ "
^
<inline asm>:1:191: note: instantiated into assembly here
/* MMX code for inner loop of X bilinear filter */ movl -36(%rbp), %ecx; pxor %mm0, %mm0; 1: movsxl (%rdi), ...
^~~~~~
2 errors generated.
It seems rather silly to me that PyPy got stuck at a line that generates what seems to be a block comment in C. And why its encapsulated the comment in asm and volatile is beyond me. But this is the code that was provided to me and works in regular python. So is this a bug? Or am I missing something?
Chances are PyPy has some #defines different than CPython (for good or bad reasons) and pygame chooses to use something else (based on a badly thought out #else with implicit assumptions) that tries to compile invalid C. I'm just guessing though, you would need to follow why and how the same code is/is not compiled on CPython.