Hopsan / hopsan

Hopsan is a free multi-domain system simulation tool developed at the division of Fluid and mechatronic systems at Linköping university.
Apache License 2.0
157 stars 43 forks source link

Installation on OS X #1711

Open mjfwest opened 6 years ago

mjfwest commented 6 years ago

Hello, Has anyone recently built the application for OS X? The scripts in buildMacApp seem out of date. I have followed most of the instructions for debian/unix build but I have the following error when building in QTcreator.

:-1: error: No rule to make target `/Users/martinwest/Documents/repositories/hopsan/HopsanCore/dependencies/libNumHop/src/Expression.cc', needed by `Expression.o'.  Stop.
peterNordin commented 6 years ago

No, sorry, it is outdated, i recently changed a lot of things. But I do not have a Mac so I could not test this. But in this particular case, have you run git submodule update --init ?

Can you check if there is actually code in libNumHop, I have had problems where the submodule failed to download.

mjfwest commented 6 years ago

Ok. I'm happy to put some effort in to updating the build instructions and testing if I can get it to compile successfully.

Yes, the submodules were the issue there. running git submodule update --init updated libNumHop, but I believe some build script had also deleted the code from IndexingCSVParser. Manually resetting and checking out the code fixed that. I now have the following error:

compiling ../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc
In file included from ../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:25:
In file included from ../../hopsan/HopsanGenerator/include/generators/HopsanFMIGenerator.h:29:
In file included from ../../hopsan/HopsanGenerator/include/generators/HopsanGenerator.h:56:
In file included from ../../hopsan/HopsanGenerator/include/GeneratorUtilities.h:49:
In file included from ../../hopsan/Dependencies/FMILibrary/include/JM/jm_portability.h:19:
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:209:42: warning: unused parameter 'cb' [-Wunused-parameter]
static void jm_log_debug_v(jm_callbacks* cb, const char* module, const char* fmt, va_list ap) {}
                                         ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:209:58: warning: unused parameter 'module' [-Wunused-parameter]
static void jm_log_debug_v(jm_callbacks* cb, const char* module, const char* fmt, va_list ap) {}
                                                         ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:209:78: warning: unused parameter 'fmt' [-Wunused-parameter]
static void jm_log_debug_v(jm_callbacks* cb, const char* module, const char* fmt, va_list ap) {}
                                                                             ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:209:91: warning: unused parameter 'ap' [-Wunused-parameter]
static void jm_log_debug_v(jm_callbacks* cb, const char* module, const char* fmt, va_list ap) {}
                                                                                          ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:214:40: warning: unused parameter 'cb' [-Wunused-parameter]
static void jm_log_debug(jm_callbacks* cb, const char* module, const char* fmt, ...) {}
                                       ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:214:56: warning: unused parameter 'module' [-Wunused-parameter]
static void jm_log_debug(jm_callbacks* cb, const char* module, const char* fmt, ...) {}
                                                       ^
../../hopsan/Dependencies/FMILibrary/include/JM/jm_callbacks.h:214:76: warning: unused parameter 'fmt' [-Wunused-parameter]
static void jm_log_debug(jm_callbacks* cb, const char* module, const char* fmt, ...) {}
                                                                           ^
In file included from ../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:27:
In file included from ../../hopsan/HopsanCore/include/ComponentSystem.h:43:
In file included from ../../hopsan/HopsanCore/include/Component.h:38:
../../hopsan/HopsanCore/include/Port.h:336:15: warning: 'hopsan::MultiPort::addSubPort' hides overloaded virtual function [-Woverloaded-virtual]
        Port* addSubPort(const hopsan::PortTypesEnumT type);
              ^
../../hopsan/HopsanCore/include/Port.h:214:23: note: hidden overloaded virtual function 'hopsan::Port::addSubPort' declared here: different number of parameters (0 vs 1)
        virtual Port* addSubPort();
                      ^
../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:272:30: warning: unused variable 'type' [-Wunused-variable]
        fmi1_base_type_enu_t type = fmi1_import_get_variable_base_type(pVar);
                             ^
../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:1814:39: error: use of undeclared identifier 'srcFiles'
    Q_FOREACH(const QString &srcFile, srcFiles)
                                      ^
../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:1707:84: warning: unused parameter 'modelName' [-Wunused-parameter]
bool HopsanFMIGenerator::compileAndLinkFMU(const QString &savePath, const QString &modelName, int version) const
                                                                                   ^
../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:1879:76: warning: unused parameter 'modelName' [-Wunused-parameter]
void HopsanFMIGenerator::sortFiles(const QString &savePath, const QString &modelName, bool x64) const
                                                                           ^
../../hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:1879:92: warning: unused parameter 'x64' [-Wunused-parameter]
void HopsanFMIGenerator::sortFiles(const QString &savePath, const QString &modelName, bool x64) const
                                                                                           ^
12 warnings and 1 error generated.
make[1]: *** [HopsanFMIGenerator.o] Error 1
make: *** [sub-HopsanGenerator-make_first-ordered] Error 2
11:46:40: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project HopsanNG (kit: Desktop Qt 5.10.1 clang 64bit)
When executing step "Make"
11:46:40: Elapsed time: 00:03.
repositories/hopsan/HopsanGenerator/src/generators/HopsanFMIGenerator.cc:1814: error: use of undeclared identifier 'srcFiles'
    Q_FOREACH(const QString &srcFile, srcFiles)
                                      ^
peterNordin commented 6 years ago

Thank you, it would be really nice to get that stuff working again. I will assist as much as I can.

In this case I think that the problem is all the ifdefs used in the code.

They check ifdef WIN32 elif linux _ but nothing for osx.

In some cases maybe the linux code works for osx aswell, its mostly about generating build scripts (but the use of gcc might need changing)

Most of this code is horrible to read, I will try to improve it aftet I am done refactoring the generator code. (But this will take some time)

peterNordin commented 6 years ago

To make it compile, just try to change #elif linux to #else Its not critical if the generator stuff works initially

peterNordin commented 6 years ago

I have made some of these changes in my recent pull request. But I have no way of testing them.

mjfwest commented 6 years ago

I've pulled in your PR to test on os X. I'm getting an error when compiling ../../hopsan/HopsanCore/src/Quantities.cpp

make[1]: *** No rule to make target `../../hopsan/HopsanCore/dependencies/libNumHop/include/Expression.h', needed by `NumHopHelper.o'.  Stop.
make: *** [sub-HopsanCore-make_first-ordered] Error 2

it seems that the path should be ../../hopsan/HopsanCore/dependencies/libNumHop/include/numhop/Expression.h?

This might not be related to this OS X build issue.

peterNordin commented 6 years ago

Did you run 'git submodule update' ? And maybe a clean rebuild is needed. NumhopHelper.cpp includes numhop.h witch should include "numhop/Expression.h" this works with gcc at least. Could be a clang thing maybe.

mjfwest commented 6 years ago

Closed it by accident. I did a git submodule update, but I did it again to be sure and after a clean build I now get:

compiling ../../hopsan/HopsanGUI/main.cpp
../../hopsan/HopsanGUI/main.cpp:70:5: error: no member named 'locale' in namespace 'std'; did you mean 'QLocale'?
    std::locale::global(std::locale::classic());    // Set default C++ locale (should also set default C locale)
    ^~~~~~~~~~~
    QLocale
../../../../Qt/5.10.1/clang_64/lib/QtWidgets.framework/Headers/qwidget.h:93:7: note: 'QLocale' declared here
class QLocale;
      ^
../../hopsan/HopsanGUI/main.cpp:70:25: error: no member named 'locale' in namespace 'std'; did you mean 'QLocale'?
    std::locale::global(std::locale::classic());    // Set default C++ locale (should also set default C locale)
                        ^~~~~~~~~~~
                        QLocale
../../../../Qt/5.10.1/clang_64/lib/QtWidgets.framework/Headers/qwidget.h:93:7: note: 'QLocale' declared here
class QLocale;
      ^
../../hopsan/HopsanGUI/main.cpp:70:18: error: no type named 'global' in 'QLocale'
    std::locale::global(std::locale::classic());    // Set default C++ locale (should also set default C locale)
    ~~~~~~~~~~~~~^
../../hopsan/HopsanGUI/main.cpp:70:38: error: definition or redeclaration of 'classic' not allowed inside a function
    std::locale::global(std::locale::classic());    // Set default C++ locale (should also set default C locale)
                        ~~~~~~~~~~~~~^
../../hopsan/HopsanGUI/main.cpp:80:45: error: no member named 'locale' in namespace 'std'
    qDebug() << "C++ locale name: " << std::locale().name().c_str();
                                       ~~~~~^
5 errors generated.
make[1]: *** [main.o] Error 1
make: *** [sub-HopsanGUI-make_first-ordered] Error 2
15:01:40: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project HopsanNG (kit: Desktop Qt 5.10.1 clang 64bit)
When executing step "Make"
15:01:40: Elapsed time: 02:21.

This might be relevant? Stack Overflow: stdlocale segfault on os x

peterNordin commented 6 years ago

I have updated my pull request with a commit that adds the missing header to main.cpp, lets see if it works now. Hopefully the segfault thing wont happen (from the stackoverflow link)

peterNordin commented 6 years ago

Through trial and error, I have managed to make hopsan build on macos inside Travis-ci, so whenever we break macos build we will know, Since I do not have a mac, I cant test if the GUI application works.The travis build only runs non-gui tests. So there is still more work to be done. Especially on packaging. Maybe @magse can revisit this old code ?

mjfwest commented 6 years ago

I’ll get on it.

Sent from my iPhone

On 23 May 2018, at 23:25, Peter Nordin notifications@github.com wrote:

Through trial and error, I have managed to make hopsan build on macos inside Travis-ci, so whenever we break macos build we will know, Since I do not have a mac, I cant test if the GUI application works.The travis build only runs non-gui tests. So there is still more work to be done. Especially on packaging. Maybe @magse can revisit this old code ?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

peterNordin commented 6 years ago

You will need to rebuild the fmilibrary and qwt dependencies. First delete the qwt and qwt_build directories, then you may also need to reset --hard the qwt_code submodule checkout. I made some changes to the patch that is applied, that disable framework build. I could not figure out how to get that working.

mjfwest commented 6 years ago

Close! I didn't seem to have a problem with the build procedure, but when running the resultant hopsangui app in hopsan/bin I get the following crash report. it seems to not have found qt properly.

Process:               hopsangui [8547]
Path:                  /Users/USER/Documents/*/hopsangui.app/Contents/MacOS/hopsangui
Identifier:            com.tinarmengineering.hopsangui
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           hopsangui [8547]
User ID:               501

Date/Time:             2018-05-25 12:32:56.439 +0200
OS Version:            Mac OS X 10.13.4 (17E202)
Report Version:        12
Anonymous UUID:        DB412B41-08CD-8762-40CD-D09B8770A90B

Time Awake Since Boot: 6600 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Library not loaded: libqwt.6.dylib
  Referenced from: /Users/USER/Documents/*/hopsangui.app/Contents/MacOS/hopsangui
  Reason: image not found

Binary Images:
       0x10e890000 -        0x10ed08ff7 +com.tinarmengineering.hopsangui (0) <E1FCAD02-0CFD-3AC2-ABE7-8056EE04FB7E> /Users/USER/Documents/*/hopsangui.app/Contents/MacOS/hopsangui
       0x11d979000 -        0x11d9c39df  dyld (551.3) <AFAB4EFA-7020-34B1-BBEF-0F26C6D3CA36> /usr/lib/dyld

Model: MacBookPro10,2, BootROM MBP102.010D.B00, 2 processors, Intel Core i5, 2.5 GHz, 8 GB, SMC 2.6f59
Graphics: Intel HD Graphics 4000, Intel HD Graphics 4000, Built-In
Memory Module: BANK 0/DIMM0, 4 GB, DDR3, 1600 MHz, 0x80AD, 0x484D5434314753364D465238432D50422020
Memory Module: BANK 1/DIMM0, 4 GB, DDR3, 1600 MHz, 0x80AD, 0x484D5434314753364D465238432D50422020
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x10F), Broadcom BCM43xx 1.0 (7.21.190.18.1a3)
Bluetooth: Version 6.0.5f3, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
Serial ATA Device: OWC Aura, 480.1 GB
USB Device: USB 2.0 Bus
USB Device: Hub
USB Device: FaceTime HD Camera (Built-in)
USB Device: USB 2.0 Bus
USB Device: Hub
USB Device: Hub
USB Device: Apple Internal Keyboard / Trackpad
USB Device: BRCM20702 Hub
USB Device: Bluetooth USB Host Controller
USB Device: USB 3.0 Bus
USB Device: Kinesis Keyboard Hub
USB Device: Composite Device
USB Device: DIGIPASS 920
Thunderbolt Bus: MacBook Pro, Apple Inc., 23.4
peterNordin commented 6 years ago

This is similar to a problem I got with our tests requiring FMILibrary. I hade to make the qwt.pri (In Dependencies) copy the resulting file into the bin directory. As mentioned I could not test the gui applications, so I did not see this. Could you test if it works if you manually copy the needed .dylib files to the same directory as hopsangui. On Linux I would also try setting the LD_LIBRARY_PATH to include paths to where the binaries are installed, for example your qt installation director (bin or lib subdirectory). I dont know if this pathe variable is usefulk on macOS.

peterNordin commented 6 years ago

I think that hopsangui should be able to start now after my latest changes. If the Qt libraries can be found. All locally build dependencies are now copied to the bin directory during build. Not the best solution but it will have to do for now

raspe827 commented 6 years ago

Hello, I followed the travis build steps and got the hopsangui to launch and it seems hopsan seems to be working. Now i have the problem that I want to add my own components to Hopsan but do not get the compiling to work. I use Xcode with clang: Apple LLVM version 10.0.0 (clang-1000.10.44.2). but now i get the following faults when compiling in Xcode screen shot 2018-10-10 at 18 35 02

Have i missed to link something or is it a compiler issue?

peterNordin commented 6 years ago

OK some things to try.

First of all don't include the xml files into the code. This will cause compilation error as they do not contain valid c/c++ code. (Its xml formated text).

Instead include the .hpp file where you implemented your component. It seems to be missing in this case. Lets see if that solves the problem.

The xml files are used to decribe the visual appearance of the component. The code implements the equations.

peterNordin commented 6 years ago

You can also try HoLC (Hopsan library creator) to generate the library files automatically. (If you can compile it). Then you can add your .hpp and component .xml files (that you write manually) using "add existing files".

Unfortunately the compile features of holc and hopsan gui do not yet work on mac, due to being hard-coded for GCC. So you will still need to use xcode to compile the library.

raspe827 commented 6 years ago

Yes you are right, it compiled with the correct source file.

But since i have made a project for a command line tool i now have to set up a new one with a makefile instead (think this is the only way to do it in Xcode after some research), are there any makefile that could be to some help to start from in the Hopsan source since i have not done this before?

peterNordin commented 6 years ago

No there are no makefiles in the code, especially not for macOS, but you can use the same method as HopsanGenerator when compiling. Use a script that calls the compiler directly. Then you can code in xcode and then run the script manually to build the library.

Unfortunately I can not give you an example (you need to run it on linux or windows). But maybe @robbr48 can help you. Its a really simple script that just calls the compiler directly (clang in your case) with some flags. You can also look in the HopsanGenerator code and see if you can find the code that generates the script and see what to write. It will be something similar to: gcc -Ipath/to/hopsan -Lpath/to/hopsan/bin -lhopsancore yourlibrary.cpp -o yourlibrary.dylib

But you should not use gcc

peterNordin commented 6 years ago

Here is a copy of the generated script for the example library from Kubuntu, debug mode

!/bin/sh

rm -f libexamplecomponentlib_d.so gcc -g -DDEBUGCOMPILING -Dhopsan=hopsan -fPIC -w -Wl,--rpath,"/mnt/sdc2/vcs/git/hopsan/componentLibraries/exampleComponentLib" -shared exampleComponentLib.cpp -fpermissive -o libexamplecomponentlib_d.so -I"/mnt/sdc2/vcs/git/hopsan/HopsanCore/include" -L"/mnt/sdc2/vcs/git/hopsan/bin" -lhopsancore_d

Here is for release mode

!/bin/sh

rm -f libexamplecomponentlib.so gcc -DRELEASECOMPILING -Dhopsan=hopsan -fPIC -w -Wl,--rpath,"/mnt/sdc2/vcs/git/hopsan/componentLibraries/exampleComponentLib" -shared exampleComponentLib.cpp -fpermissive -o libexamplecomponentlib.so -I"/mnt/sdc2/vcs/git/hopsan/HopsanCore/include" -L"/mnt/sdc2/vcs/git/hopsan/bin" -lhopsancore

peterNordin commented 6 years ago

I do not think that -Wl,--rpath,"..." is neede, also, it wont work on macOS not sure about -fPIC on macOS, try without if it fails In your case the -I flag should not have the /include at the end since you have that in the code.

raspe827 commented 6 years ago

Okey thank you! I will have a go on it and see if i can I can get it working

peterNordin commented 5 years ago

I forgot to mention, the most obvious way to include your components. Since you are already building Hopsan from source, you can include you code in the default library, or maybe the exampleComponentLibrary, then it will be built using the Hopsan build system every time you rerun the Hopsan build. It will take slightly longer then only building your library, but you wont have to get your own build system working.

raspe827 commented 5 years ago

Hello @peterNordin, After some tries and some reading around on stack overflow i found this: https://stackoverflow.com/questions/30174180/link-osx-homebrew-gfortran-against-libc and tried it out, and now I can build my components from terminal with: rm -f libelectromagnet.dylib gcc -lc++ -DRELEASECOMPILING -Dhopsan=hopsan -fPIC -w -Wl,-rpath,"/Users/rasmuspersson/Documents/hopsan_test_again/hopsan_test_again" -shared electromagnet.cpp -fpermissive -o libelectromagnet.dylib -I"/Users/rasmuspersson/HopsanCore/include" -L"/Users/rasmuspersson/Hopsan/hopsan/bin" -lhopsancore

Thanks for the help!