Skip to content

Instantly share code, notes, and snippets.

@robodhruv
Last active July 21, 2024 23:06
Show Gist options
  • Save robodhruv/e2c0945cc78006b00d4206846bdb7657 to your computer and use it in GitHub Desktop.
Save robodhruv/e2c0945cc78006b00d4206846bdb7657 to your computer and use it in GitHub Desktop.
Installing ModelSim on Ubuntu

ModelSim Installation issues

Ubuntu 14.xx and above

Ignore this if you have not encountered any issue with the installation and running of ModelSim and Quartus on your system. You are very lucky. (Just Kidding! You have surely had this issue, only sorted.)

Hence assuming you have been following the procedure given in this guide. Most certainly, Quartus will install jsut fine, and so will ModelSim. The issue is in launching due to inappropriate linking etc.

Stage 1

This is the simplest error you would encounter. Navigate to the modelsim_ase folder and run:

cd /opt/modelsim_ase/bin/
./vsim

Unless you have not updated your Linux kernel in the last 3 years, you are most certain to encounter an error saying could not find ./../linux_rh60/vsim. To understand this (optional) you can open the file vsim and notice that in the if...elseif conditions, the default description points towards a folder for the Red Hat distro.
(This setup will only work for you without changes IF your Linux kernel is 3.x or below. Highly unlikely. Check using uname -r).

Okay, all of that aside, basically you need to replace this as (sudo is your friend!) :

*)                vco="linux" ;; # This is most likely to be line 212 (initially vco="linux_rh60")

Also, change the very first non-commented line to:

mode=${MTI_VCO_MODE:-"32"}

This should be adequate for most of you, and running /opt/modelsim_ase/bin/vsim will open a plain boring GUI. For that lot, thanks a lot for sticking around! Hope it helped. The others, keep following.

Stage 2

Here is where things get nasty. Does running the vsim script lead to:

** Fatal: Read failure in vlm process (0,0)
Segmentation fault (core dumped)

If yes, hang on. If not, I am sorry! Google is your friend!

I am guessing this issue came up for me because of the infinite existing packages on my system, including ROS. That seems to have ruined the setup for me, and hence more learning about the intricacies of compilation and linking. Totally worth it!

Okay, so here's what you would have to do. You probably need to build a new version of freetype, a font setting library and modify ModelSim to use it. You can download the source code for freetype here.

sudo apt-get build-dep -a i386 libfreetype6
# The above forced me to uninstall my ROS packages, and well.. I had no choice. Temporarily, let's remove them and proceed
cd ~/Downloads/
cd freetype-2.4.12
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make -j8

Most certainly, the above would give you an error looking like:

checking whether the C++ compiler works... no
...
configure: error: C++ compiler cannot create executables

This is because you could be on a 64-bit system but you will also need the 32-bit versions of the libraries that it depends on. After an hour of fretting, here's what you'll have to do.

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential
# You already had build-essential and gcc, g++ etc. But you will also need to install the 32 bit versions.

sudo apt-get install gcc-multilib g++-multilib \
lib32z1 lib32stdc++6 lib32gcc1 \
expat:i386 fontconfig:i386 libfreetype6:i386 libexpat1:i386 libc6:i386 libgtk-3-0:i386 \
libcanberra0:i386 libpng12-0:i386 libice6:i386 libsm6:i386 libncurses5:i386 zlib1g:i386 \
libx11-6:i386 libxau6:i386 libxdmcp6:i386 libxext6:i386 libxft2:i386 libxrender1:i386 \
libxt6:i386 libxtst6:i386

This just about solves the dependency issues and compiler errors. Run the following inside freetype... folder.

./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make -j8

This should nicely compile and give you the libraries in the directory objs/.libs/. Move this to the modelsim_ase folder and define the linkings. Almost done here...

mkdir /opt/modelsim_ase/lib32

sudo cp ~/Downloads/freetype-2.4.12/objs/.libs/libfreetype.so* /opt/modelsim_ase/lib32

sudo vim /opt/modelsim_ase/bin/vsim

Find the line which says

dir=`dirname $arg0`

(Note that this occurs in multiple locations. In simple terms, look at the one in the main sequence of execution, and not in the if statement. You can ignore the one under CYGWIN. Cygwin is for Windows. Windows is for losers! :p Apologies.)

Below this add the line:

export LD_LIBRARY_PATH=${dir}/lib32

Save this file. This would only be possible if you have sudo permissions. And finally!

cd /opt/modelsim_ase/bin/
./vsim

Hopefully, a plain boring GUI will show up!

Hope this helped. Cheers!
Dhruv

@Kunkka1988
Copy link

Thanks. The confliction between freetype/fontconfig and vsim is root cause.
We don't have to select and use the 32bit vsim.

@benjamin051000
Copy link

benjamin051000 commented Sep 17, 2022

Not working in Fedora 36 (I doubt this is a supported OS but Quartus works fine so I'm not sure what's up with modelsim)

  • Modelsim 20.1 Lite
  • I set the custom installpath to be ~/.intelFPGA because I like to hide as much as possible in my homedir. Let me know if you think this could be the culprit
$ ./vsim
./vsim: line 182: /home/benjamin/.intelFPGA/20.1/modelsim_ase/bin/../linux/vsim: No such file or directory

But when I actually check that dir,

$ cd /home/benjamin/.intelFPGA/20.1/modelsim_ase/bin/../linux/    

$ ll | grep vsim
-rwxr-x---. 1 benjamin benjamin 6.8M Feb 28  2020 vsim
-rwxr-x---. 1 benjamin benjamin  35M Feb 28  2020 vsimk
-rw-r-----. 1 benjamin benjamin  87M Feb 28  2020 vsimk32.esf
-rw-r-----. 1 benjamin benjamin 170K Feb 28  2020 vsimka.mdb

$ file vsim
vsim: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=14c9896a96df1d7224e4fd03ef7434e6432af57c, stripped

It's definitely there! What's going on? Even if I try to run this executable directly it doesn't work.

@lf-
Copy link

lf- commented Sep 17, 2022

@benjamin051000 that's actually a dynamic linker error. try running ldd with that executable path and see what it says. I expect you will find a missing library.

@benjamin051000
Copy link

@lf- This is what I'm seeing on Fedora 36:
image
The only thing I did that was non-standard is install to .intelFPGA so the file is hidden, but this shouldn't matter as far as I know. I'm not really sure how vsim startup works but I find it really weird that trying to run ./linux/vsim yields this error when file definitely sees it...

@yhkwon6658
Copy link

yhkwon6658 commented Sep 10, 2023

@benjamin051000
Centos also has same trouble shooting. I think this solution is for only ubuntu.
However, I found something.
vsim command mode is well working.
E.g.) vsim -c -do "vlib work; vlog *.v *.sv; vsim tb; run -all; quit"
It's work well for Dispalying to the terminal or File I/O
Also, I know using questasim(not modelsim) doesn't make any problem.

@benjamin051000
Copy link

@yhkwon6658 I have recently found that using https://github.com/89luca89/distrobox is the easiest solution of all: It containerizes your tool and allows you to choose a distro that the tool officially supports. This is my current go-to solution.

@bkw777
Copy link

bkw777 commented Jul 21, 2024

quartus 13.0 and it's bundled modelsim on ubuntu 23.10
(to support devices not supported in 13.1 or later)

There is an arch pkg of pre-built freetype libs that work, so this recipe has no compile steps and no need to temporarily mess up your system due to installing conflicting dependencies just to build freetype.

https://gist.github.com/bkw777/a6a2888f482802f2e520165858268cd3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment