Posts Tagged ‘llvm’

Compile and run mesa on bluehost web server

Sunday, October 7th, 2012

I want to use the off-screen renderer of Mesa in a php script on my blue host served website. Compiling Mesa on my mac was dead simple (sudo port install mesa), but doing it on the linux server without root access or repositories was a bit tricky. Here’s how I finally got it to work.

Download and compile llvm, if it’s not around already. I found that version 3.1 didn’t play nicely with Mesa but 3.0 did. LLVM installed smoothly.


./configure --prefix=[INSTALL_PREFIX]
make -j5
make install

Next, grab the latest glproto headers. As far as I can tell, there is nothing to compile as only headers are needed.

Download mesa, unzip and compile using the following:


% Set up glproto headers
export GLPROTO_LIBS=../glproto-1.4.16/;
export GLPROTO_CFLAGS=../glproto-1.4.16/;
% configure, disabling DRI support (i.e. graphics card support)
./configure --prefix=[INSTALL_PREFIX] --disable-driglx-direct --enable-xlib-glx --enable-osmesa --disable-dri
make -j5
make install

Then I got the Mesa demos and made sure I could compile src/osdemos/osdemo.c:


gcc -o osdemo osdemo.c -I[INSTALL_PREFIX]/include -L[INSTALL_PREFIX]/lib -lOSMesa -lGLU

Upon running osdemo, you might see:


./osdemo: error while loading shared libraries: libOSMesa.so.8: cannot open shared object file: No such file or directory

But this is fixed by adding you library install path to the LD_LIBRARY_PATH variable:


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:[INSTALL_PATH]/lib/

or in php:


putenv("LD_LIBRARY_PATH=".$_ENV["LD_LIBRARY_PATH"].":[INSTALL_PATH]/lib/");

If it works then you can run the program with:


./osdemo foo.tga

and produce an image like:
output of osdemo of mesa demos running on web server

Casting bug in g++ llvm 4.2 int to double

Monday, July 2nd, 2012

The following code seems to compile incorrectly using g++, llvm version 4.3 with -O3:


#include <iostream>

int main(int argc,char * argv[])
{
  using namespace std;
  // loop over canonical view quaternions
  for(int sign = -1;sign<=1;sign+=2)
  {
    std::cout<<sign<<" --> "<<(double)sign<<std::endl;
    // Necessary to reproduce bug
    for(int i = 0; i<1; i++)
    {
      for(int j = 0;j<1;j++)
      {
      }
    }
  }
  return 0;
}

For some reason it is not casting the int, rather it seems to be just reinterpreting the bits as a double.

Switching off compile optimization, switching to plain old g++ or switching to float instead of double works, but are not helpful in my case. Instead I did something that works, but is likely non-optimal, I replaced the double cast with a float cast followed by a double cast.


(double)(float)sign

Linking against static library using Eigen produces many direct access ... to global weak symbol warnings

Friday, April 13th, 2012

Our group builds a static library of useful functions implemented using the Eigen matrix library in C++. We build the library with a standard Makefile and gcc. But when I try to link against this library in an Xcode project (which also used Eigen) I got many warnings from the linker of the form:


ld: warning: direct access in void Eigen::internal::computeProductBlockingSizes<float, float, 4>(long&, long&, long&)to global weak symbol Eigen::internal::manage_caching_sizes(Eigen::Action, long*, long*)::m_l2CacheSizemeans the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

There seem to be no problems at runtime, but nonetheless it’s annoying to have so many warnings.

To make the warnings go away, I went to my project settings in Xcode and made sure that Symbols Hidden by Default was set to No.

Xcode symbols hidden by default