Why do some of the samples on the website work and some don't?

52 views
Skip to first unread message

lc Z

unread,
Jul 26, 2022, 1:56:15 AM7/26/22
to ogdf
I have installed OGDF on my Windows platform and have done some configuration. (visual studio 2022). I tried the following example from the official website:


I found that the following example can run.

#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
#include <ogdf/fileformats/GraphIO.h>

using namespace ogdf;

int main()
{
    Graph G;
    randomSimpleGraph(G, 10, 20);

    DfsAcyclicSubgraph DAS;
    DAS.callAndReverse(G);

    GraphIO::write(G, "output-acyclic-graph.gml", GraphIO::writeGML);

    return 0;
}

QQ图片20220726135034.png


 But when I ran another example, it prompted some errors.

#include <ogdf/basic/graph_generators.h>
#include <ogdf/planarity/SubgraphPlanarizer.h>
#include <ogdf/planarity/PlanarSubgraphFast.h>
#include <ogdf/planarity/VariableEmbeddingInserter.h>
#include <ogdf/fileformats/GraphIO.h>
 
using namespace ogdf;
 
int main()
{
    Graph G;
    randomSimpleGraph(G, 100, 150);
 
    SubgraphPlanarizer SP;
    SP.setSubgraph(new PlanarSubgraphFast<int>);
    SP.setInserter(new VariableEmbeddingInserter);
 
    int crossNum;
    PlanRep PR(G);
    SP.call(PR, 0, crossNum);
 
    std::cout << crossNum << " crossings" << std::endl;
    GraphIO::write(PR, "output-plan.gml", GraphIO::writeGML);
 
    return 0;
}

aa.png
I don't understand why the second example would produce two errors.






Dagobert Smart

unread,
Aug 1, 2022, 8:22:16 AM8/1/22
to ogdf

Hello!

I assume that you have turned on the cmake switch OGDF_USE_ASSERT_EXCEPTIONS, which causes OGDF_ASSERT to contain calls of ogdf::get_stacktrace().
However, your linker cannot find the get_stacktrace() function. Because of that, code that uses OGDF_ASSERT does not link correctly.
(However, the examples that do not contain OGDF_ASSERT link correctly.)

The code that defines get_stacktrace() is in src/ogdf/external/backward.cpp. You lib/dll file does not seem to contain that code…
I have an idea for potential fix: Does it help when you add OGDF_EXPORT in front of the declaration of get_stacktrace() (include/ogdf/basic/basic.h, line 131)?
It should look like this:

OGDF_EXPORT extern void get_stacktrace(std::ostream &);

Does that help?

Best regards,
Dagobert

lc Z

unread,
Aug 3, 2022, 8:08:50 AM8/3/22
to ogdf

Hello,
I added `` OGDF_EXPORT ``according to your suggestion, but the error is still as follows:

```
Severity    Code    Description    Project    File    Line    Suppression State Error    LNK1120    1 unresolved externals    myogdf    E:\Z_EXOGDF\myogdf\x64\Debug\myogdf.exe    1    

Severity    Code    Description    Project    File    Line    Suppression State
Error    LNK2019    unresolved external symbol "__declspec(dllimport) void __cdecl ogdf::get_stacktrace(class std::basic_ostream<char,struct std::char_traits<char> > &)" (__imp_?get_stacktrace@ogdf@@YAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z) referenced in function "public: int & __cdecl ogdf::Array<int,int>::operator[](int)" (??A?$Array@HH@ogdf@@QEAAAEAHH@Z)    myogdf    E:\Z_EXOGDF\myogdf\myodgf.obj    1    
```
Best wishes.
Licheng Zhang.

Dagobert Smart

unread,
Aug 8, 2022, 9:37:44 AM8/8/22
to ogdf

Hello again Licheng Zhang,

I was able to replicate the linker error, but for me it was fixed by the OGDF_EXPORT (I also added the name of the parameter stream but I don’t think that should make a difference).

OGDF_EXPORT extern void get_stacktrace(std::ostream &stream);

The test test-assert also had a little bug where two variables were declared as int even though they are bools. But that is only a problem with that specific test and not with the rest library or the examples.

My only other suggestion is to make sure that you recompile the OGDF library after adding the OGDF_EXPORT. Other than that, I’m afraid I don’t know why your lib/dll file would not contain the definition of get_stacktrace().

Best regards,
Dagobert

lc Z

unread,
Aug 30, 2022, 9:39:24 PM8/30/22
to og...@googlegroups.com
Hello again Dagobert
Thank you for your help.  I switched to Linux and so far so good.
Best regards,
Licheng Zhang

Dagobert Smart <dagobe...@gmail.com> 于2022年8月8日周一 21:37写道:
--
You received this message because you are subscribed to a topic in the Google Groups "ogdf" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ogdf/oyNe4MJNCPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ogdf+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ogdf/f1a18302-5234-471d-8d91-59bf83a200f1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages