Cevelop / Issues

The official issue tracker for Cevelop.
9 stars 1 forks source link

Linking static libraries #92

Closed nturumel closed 5 years ago

nturumel commented 5 years ago

Expected Behavior

Please tell us what you expected to happen. If possible, include some sample code for us to reproduce what you're seeing.

Actual Behavior

What happened instead? If you have a screenshot or stack trace of the error, please attach it.

Cevelop Version, Operating System and Compiler

The more we know about your setup, the easier it will be for us to reproduce the problem.

nturumel commented 5 years ago

i have a static library .a file that I created, I want to add it to another project, what should I do? Currently I copy it to the project and then goto properties, C++ build options and add a library there, in the library path option, however, it gives me a -lC://.... cannot locate sample.a file, even though it is there. Is it a parsing problem?

tonisuter commented 5 years ago

Hi

There are two ways you can do this in Cevelop. If the library is a separate Cevelop project in the same workspace, you can do the following:

  1. Open the properties of the executable project.

  2. Go to C/C++ General -> Paths and Symbols -> References

  3. Add a reference to the library project. This will automatically set the library path, header path, etc.

The end result should look like this: bildschirmfoto 2019-03-07 um 10 36 17

If you instead want to add the library and its header files directly to the executable project, you can do that as well. However, this means that you need to manually specify the library path, library name, etc:

  1. Open the properties of the executable project.

  2. Go to C/C++ General -> Paths and Symbols -> Library Paths and add the path to the library as a workspace path. bildschirmfoto 2019-03-07 um 10 47 53

  3. Go to C/C++ General -> Paths and Symbols -> Libraries and add the name of the library (without the lib prefix and the .a file extension). bildschirmfoto 2019-03-07 um 10 47 59

I hope this fixes your problem. Otherwise, please let us know.

nturumel commented 5 years ago

I tried to do that, but I still have issues, as I mentioned before I need to link the lib.a file in this case libSignalStatisticsLibNihar.a file and the header file to my executable, even if it means to copy both the .hpp and the .a to the executable folder, can you help me with it?

nturumel commented 5 years ago

1- this is the library header and the executable 2- added reference 3-built 4-run config 5-run failed

PeterSommerlad commented 5 years ago

Your build went perfectly. And since it is a static library it will be included in your exe file.

What might be missing is the compiler's run-time library (DLL). Depending if you are using g++ on windows through cygwin or mingw different reasons might be the case. Can you run the exe in a command prompt window. If it is cygwin, does it run in cygwn's bash, if it you are using mingw can you run it in a regular command prompt. You might need to add the compiler's runtime DLL's location to your path. I remember from 10+ years ago, it was recommended for Cygwin users to copy the cygwin DLL into the WINDOWS directory to have it always available.

nturumel commented 5 years ago

image

nturumel commented 5 years ago

I think there might be something else, is there a way to use just the header and the archive of the library and hide the implementation?

PeterSommerlad commented 5 years ago

So, your program linked just fine, but does neither run from Cevelop nor from the command line.

did your test your compiler's installation on your windows computer by itself, e.g. by compiling a simple hello world c++ program with it. if that does run, then there might be something.

However, to further diagnose, I suggest that you provide more information about your windows and g++ setup, because the problem definitely does not seem to be rooted in Cevelopl, but in your underlying compilation/execution setup.

You are using the 32 bit command prompt. May be your program was compiled for 64 bit.

  1. What Windows Version are you using (version, 32 or 64 bit)

  2. What compiler (version) are you using for compilation (cygwin/mingw, 32/64bit, version of g++)?

  3. Can you compile and run a minimal C++ program?

Otherwise, everything is just speculation.

BTW, you should have provided all that information when you initially filed the bug

nturumel commented 5 years ago

I am able to compile and run hello.cpp program

On Thu 7 Mar, 2019, 12:05 PM Peter Sommerlad, notifications@github.com wrote:

So, your program linked just fine, but does neither run from Cevelop nor from the command line.

did your test your compiler's installation on your windows computer by itself, e.g. by compiling a simple hello world c++ program with it. if that does run, then there might be something.

However, to further diagnose, I suggest that you provide more information about your windows and g++ setup, because the problem definitely does not seem to be rooted in Cevelopl, but in your underlying compilation/execution setup.

You are using the 32 bit command prompt. May be your program was compiled for 64 bit.

1.

What Windows Version are you using (version, 32 or 64 bit) 2.

What compiler (version) are you using for compilation (cygwin/mingw, 32/64bit, version of g++)? 3.

Can you compile and run a minimal C++ program?

Otherwise, everything is just speculation.

BTW, you should have provided all that information when you initially filed the bug

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Cevelop/Issues/issues/92#issuecomment-470610009, or mute the thread https://github.com/notifications/unsubscribe-auth/Ar1co6DeBCXVBwNdQM1tQxS-W0k5WzuNks5vUUbogaJpZM4bh2ZI .

nturumel commented 5 years ago

Sorry, I will provide all the information in the future

On Thu 7 Mar, 2019, 12:07 PM Nihar Turumella, nturumel@andrew.cmu.edu wrote:

I am able to compile and run hello.cpp program

On Thu 7 Mar, 2019, 12:05 PM Peter Sommerlad, notifications@github.com wrote:

So, your program linked just fine, but does neither run from Cevelop nor from the command line.

did your test your compiler's installation on your windows computer by itself, e.g. by compiling a simple hello world c++ program with it. if that does run, then there might be something.

However, to further diagnose, I suggest that you provide more information about your windows and g++ setup, because the problem definitely does not seem to be rooted in Cevelopl, but in your underlying compilation/execution setup.

You are using the 32 bit command prompt. May be your program was compiled for 64 bit.

1.

What Windows Version are you using (version, 32 or 64 bit) 2.

What compiler (version) are you using for compilation (cygwin/mingw, 32/64bit, version of g++)? 3.

Can you compile and run a minimal C++ program?

Otherwise, everything is just speculation.

BTW, you should have provided all that information when you initially filed the bug

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Cevelop/Issues/issues/92#issuecomment-470610009, or mute the thread https://github.com/notifications/unsubscribe-auth/Ar1co6DeBCXVBwNdQM1tQxS-W0k5WzuNks5vUUbogaJpZM4bh2ZI .

PeterSommerlad commented 5 years ago

can you do that from Cevelop? Or only on the command line? Again, which g++ are you using?

nturumel commented 5 years ago

Thank You, I can run a sample file from cevelop, not from my terminal, I am sing mingw 0.6.3, is there any way I can upload my executable project folder and have someone help me please?

PeterSommerlad commented 5 years ago

The problem you are having is definitely a 32/64 bit problem, if my google foo is not wrong and has nothing to do with Cevelop. If you can not provide the information I asked for, I can not be of further help. I won't debug your executable (which I doubt is the problem). I expect everything you are running is 64bit. But may be the option set in your mingw compilation targets 32 bit and such a program might not run on your system or vice versa.

PeterSommerlad commented 5 years ago

we usually recommend our students to use https://nuwen.net/mingw.html installation. However, this requires some adjustments (see cevelop FAQ), so that Eclipse CDT detects the compiler. current is Version 6. if your version number is correct it seems very old, it might be just that the .exe generated is not compatible with your windows version.

nturumel commented 5 years ago

Thank you for your help, I understand as, I am operating on a 64 bit os, and I am using the mingw 0.6.3, I will take a look at the link you sent me