moovweb / gokogiri

A light libxml wrapper for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can't seem to easily build on OS X

mattetti opened this issue · comments

The README is obviously outdated since the makefile is gone, but I still didn't manage to build/install on Mountain Lion:

https://gist.github.com/4383203

I installed libxml2 from homebrew, updated the xpath import statement to reflect the path of the brew files.
Tried to build and go some error.

An updated readme would be very appreciated since this lib seems very useful.

Thanks,

  • Matt

Readme is updated. Pls try again, Matt. Thanks

$ go get github.com/moovweb/gokogiri
# pkg-config --cflags libxml-2.0 libxml-2.0
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
exit status 1

I have the system libxml installed as well as the homebrew version. I tried to set PKG_CONFIG_PATH but didn't manage to get passed this issue.

Yes, thanks for the reminder. Neither the system nor the brew version supports pkg-config. And it creates even more issues to give the absolute path in the source code.

You can use this repo: https://github.com/zhigangc/libxml2-2.7.8

This is 2.7.8 with a few minor changes: add pkg-config support and comment out some unnecessary checks.

Or you can add pkg-config manually to your existing installation as follows:

You should use the brew version of libxml2, and should NOT use the system version.

  1. You need to verify that your pkg-config is in your local bin as

/usr/local/bin/pkg-config

  1. Usually libxml2 is installed at

/usr/local/Cellar/libxml2/2.7.8

You need to create a dir

/usr/local/Cellar/libxml2/2.7.8/lib/pkgconfig

  1. In the pkgconfig dir, you should have the file: libxml-2.0.pc, and its content as

prefix=/usr/local/Cellar/libxml2/2.7.8
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
modules=1

Name: libXML
Version: 2.7.8
Description: libXML library version2.
Requires:
Libs: -L${libdir} -lxml2
Libs.private: -lpthread -lz -liconv -lm
Cflags: -I${includedir}/libxml2

Note if your installation is not at /usr/local/Cellar/libxml2/2.7.8, you need to change the prefix properly.

  1. Then you need to create a symbolic link

sudo ln -s /usr/local/Cellar/libxml2/2.7.8/lib/pkgconfig/libxml-2.0.pc /usr/local/lib/pkgconfig/libxml-2.0.pc

  1. At last, verify if you have it with pkg-config

pkg-config --libs libxml-2.0

You should have something like

-L/usr/local/Cellar/libxml2/2.7.8/lib -lxml2

Homebrew's libxml-2.0 2.8.0 has pkgconfig support. For anyone coming here for answers, you only need to do the final steps:

  1. Create symbolic link.

    sudo ln -s /usr/local/Cellar/libxml2/2.8.0/lib/pkgconfig/libxml-2.0.pc \
    /usr/local/lib/pkgconfig/libxml-2.0.pc
  2. Check with pkg-config:

    pkg-config --cflags libxml-2.0 libxml-2.0

I got this as result: -I/usr/local/Cellar/libxml2/2.8.0/include/libxml2

This also occurs on Windows

Did the steps outlined above help fix the issues in windows?

No, it remained unfixed :(

@acron0 could you open a new github issue describing the trouble you're having when building on windows?

This issue happened on my linux mint, too. After installing libxml2-dev, issue solved.

As @vampirewalk said installing libxml2-dev solves the issue:

$ sudo apt-get install libxml2-dev
$ go get github.com/moovweb/gokogiri

on ubuntu 12.04

Yup, I'll make note of it in the readme.

Ok, after really long suffer, and trying everything on the internet I finally successfully compiled everything on OS X 10.9 Mavericks this way

brew install apple-gcc42 
export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
brew install libxml2
sudo ln -s /usr/local/Cellar/libxml2/2.9.1/lib/pkgconfig/libxml-2.0.pc /usr/local/lib/pkgconfig/libxml-2.0.pc
go get github.com/moovweb/gokogiri

AHHHHH! sorry, I have been trying this the whole day!

Thanks for everyone who shared their hints.

@allochi 's tip solved the problem, thx!

@allochi 's process doesn't work for me in Mavericks 10.9.5, I get the following errors:

# github.com/moovweb/gokogiri/help
In file included from /private/tmp/src/github.com/moovweb/gokogiri/help/help.go:6:
/usr/local/Cellar/libxml2/2.9.1/include/libxml2/libxml/tree.h:15:19: error: stdio.h: No such file or directory
In file included from /usr/local/Cellar/libxml2/2.9.1/include/libxml2/libxml/tree.h:16,
                 from /private/tmp/src/github.com/moovweb/gokogiri/help/help.go:6:
/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include/limits.h:10:25: error: limits.h: No such file or directory
In file included from /usr/local/Cellar/libxml2/2.9.1/include/libxml2/libxml/parser.h:810,
                 from /usr/local/Cellar/libxml2/2.9.1/include/libxml2/libxml/globals.h:18,
                 from /usr/local/Cellar/libxml2/2.9.1/include/libxml2/libxml/threads.h:35,
...

fyi - I had this problem to and needed to brew install pkg-config

See https://github.com/lestrrat/go-libxml2/issues/23