link to library not kept after saving a gds

Hi all,

by means of this forum I tried to find out as much as possible about libraries in KLayout.
I'm working with KLayout on a Windows platform and created some libraries in the
folder I also have access to implement these libraries in a gds design file. They are then included as a LIB1.instancename in the gds which should mean that the content of this LIB1 libraries is linked to the library LIB1.

So far so good.

The problem I have is, that as soon as I save and close the gds file, the link gets lost. Reopening the gds file still shows the content of the library but it is not linked anymore. I can directly modify the content and also the LIB1.instancename changed to instancename only.

Do you have any hint what I'm doing wrong?

Best regards


  • edited June 2018

    Hi Dirk,

    KLayout tries to preserve the libraries, but in order to do so, it needs two things:

    • An annotation inside the GDS file telling it that a cell is a library cell. KLayout creates this annotation by writing a special top cell in addition to the other cells. This cell is not written, if you use "Save selected cell as" for example. If you use third-party tools to process your layout, they may remove this annotation cell as well.
    • The libraries need to be there when you load the layout again. This is usually the case, but if you load a file on an installation that does not have these libraries, the link gets disconnected.

    You can try saving and loading to OASIS. OASIS uses a different method for annotations (file properties). So if it works for OASIS, but not for GDS2, the problem is due to this special top cell.


  • Hi Matthias,

    thanks for your comment.
    I can ensure that the GDS files, not the library GDS and also not the layout GDS that shall contain the library GDS is modified by 3rd party tools, meaning I should be safe here. Also the installation, it's only one which is used, is always equipped with a library folder that includes the library files that I want to use in other GDS layouts.

    "An annotation inside the GDS file telling it that a cell is a library cell. KLayout creates this annotation by writing a special top cell in addition to the other cells"
    I guess this is seen by getting a cell called "LIB.cellname" in the layout file after implementing an instance called "cellname" from the library, isn't it?!
    Then I would say everything works fine, as this is exactly the case. Unfortunately, after saving the layout, closing the file and after reopening the layout, the formerly named "LIB.cellname" cell is now named as only "cellname". So there is no link to the GDS in the library anymore. That's quite frustrating as one has to modify each cell by its own when it's used in different layout files instead of simply modifying the library file which passes then directly to the various layout files.

    I'll try to use OASIS then which unfortunately is not the preferred format for us to exchange the layout data :-(.

    But thanks for your comment so far.
  • Hi Dirk,

    "An annotation" means an additional top cell, not the name of the cell.

    "LIB.cellname" is actually called "cellname" inside the GDS file. So if you open it with another tool, you just see "cellname". But you'll see another top cell called "$$$KLAYOUTCONTEXT$$$" (or similar) where KLayout stores information to keep your cell linked to the library.

    Saving a layout and restoring it SHOULD work. So I wonder what's wrong. Either KLayout does not save the link or it does not restore it.

    Here are some more questions:

    • What's the version you're using?
    • Maybe there are multiple libraries with the same name (LIB)?
    • Could you send an example with a small file that you saved and which does not properly load back?



  • One more thing: when you use "save as" - do you have the "Cell context" option ON? If it's OFF, you won't save the context information and KLayout can't restore the library links.


  • edited June 2018

    And one more thing: I noticed that when you run a library-connected layout from the command line, the library may not be linked back.

    Is the problem there also if you use "File/Open"? Then I need to look in that direction.

    I have opened a bug for this.



  • Hi Matthias,

    I re-checked the points you mentioned and you already found the solution.
    Nevertheless, I want to answer to your comments for clarification:
    1. Version is 0.25.3
    2. Each file is saved with different LIB name
    3. Don't think it's nececcary anymore, but I attach example files
    4. "Cell context" option was always checked.
    5. This was the solution. I'm using the windows platform. Opening the files by double click on the gds file opens KLayout automatically. In this case, the link is lost. Opening the gds by using the dialog menue "File --> Open..." the links are existent. Looks like this is the bug you already mentioned.

    Matthias, as you are already working on the bug: Is there a possibility to implement something like re-read the library content - maybe connected with the "Reload" in the file menue. Currently one has to close and to re-open KLayout to see new library files in KLayout.

    Attached you can findd 3 files, hopefully self-explaining.

    Best regards and many thanks!!


    PS: uploading gds format seems not to be allowed. But I think, we don't need it anymore.

Sign In or Register to comment.