How do I statically link to a lib when creating a command line program in xcode? - c

I'm new to OSX and XCode and I'm trying to statically link to a C app. I downloaded and installed libconfig and I link to the installed libconfig.a. It works great on my machine but when I run my binary on another machine I get an error that says libconfig.dylib can't be found. Naturally, I don't want to have to install libconfig everywhere I use my app.
I've scoured through the xcode build settings and the only reference I see is the one for libconfig.a. What am I doing wrong?

I got this to work. This seems to be a libconfig build issue, maybe expected behavior but it surprised me. I was linking to libconfig.a, but it appears that libconfig.a was linking to libconfig.dylib. I reconfigure libconfig and reinstalled it.
./configure --disable-shared
make clean
make
make install

Related

Mingw gives my a libwinpthread-1.dll was not found error when compiling code

I just downloaded and installed Mingw. I also setup the system environment variables for C:\MinGW\bin and C:\MinGW\msys\1.0\bin. I wanted to test to see if I had installed it correctly (it seemed to be since running gcc --version worked), so I wrote hellow world in c and tried to compile with gcc main.c -o hello_world.exe. However I got the error:
"The code execution cannot proceed because libewinpthread-1.dll" was not found. Reinstalling the program may fix this problem."
I have tired reinstalling it and restarting my computer. I have also tried to see if this problem has occurred to others, and while there are a few places it is mentioned, I can't seem to find a solution mentioned. I have thought about trying to download the dll separately, but if I remember correctly, downloading dlls is a big no no.
Awhile ago I installed mingw though chocolatey and it seemed to be working. I have deleted that download from my computer and removed the paths, since I wanted to try to install it the normal way. Could this be part of the error?
Any ideas what the issue could be? Thanks!
You have built an .exe file that depends on libwinpthread-1.dll.
Solutions to make sure the .exe can run:
Add the MinGW bin path to your PATH so libwinpthread-1.dll - this would only fix it for your own system so I wouldn't recommend this if you want to use the .exe file on other systems.
Copy libwinpthread-1.dll from MinGW in the same folder as your .exe file. This is generally needed for any shared dependancy library your .exe is linked against.
Build a static .exe (--static linker flag) to avoid the shared (.dll) dependancy.
Yes! probably is an error, cause MinGW is a bit stinky when it comes to DLLs
Here are some things you have to check:
Make sure the variable helding the location of MinGW is named "path"
and its pointing at: C:\MinGW64\bin

Xcode cannot find installed library

I am using Mac OS X 10.8 with Xcode. I have installed the jansson library, with the following commands:
./configure
make
make check
sudo make install
Everything went fine and the library installed correctly. I have created a smple .c file with a text editor and tried to include the <jansson.h> file. I builded everything and it gave no errors, meaning that the library is installed on my system.
Now, Xcode doesn't find the library at all, saying that <jansson.h> is not found. I have tried to restart my Mac, but nothing happens. If anyone knows a possible solution, I will be grateful. Thanks!
I resolved the issue, by going under Build phases, and searching for HEADER_SEARCH_PATH. Then I changed the search path label with /usr/local/include, where the library was installed.

(Mac OSX) Adding libraries to C -specifically gnuplot

I am a begineer trying to get code in C. I am working on a Mac and using xcode. My only past experience has been with java using eclipse and everything was pretty straight forward. I have almost no experience with terminal.
I am required to learn a bit of C for a project I will be working on and the learning of syntax is coming along okay, but I am at a point where I need to include some libraries in my c program. Specifically I am attempting to make plots with gnuplots.
I have downloaded gnuplot-4.6.3 from their repository and I do not even know how to install the files. I have been looking around and have tried using terminal to use the ./configure command when I am in the gnuplot-4.6.3 directory. But I really don't know what I am doing so I don't even know where to go next or what to do next.
Sorry if this is so trivial, I honestly just have never done this before and I cannot find a good tutorial on what to do.
Thanks for any help you can offer.
I would recommend using MacPorts for installing third-party tools and libraries. It knows the dependencies required and will install them as part of the installation.
Download it from macports.org.
Install it, and allow it to modify your ~/.profile so that /opt/local/bin is in your $PATH (any issue then just do export PATH=/opt/local/bin:$PATH from the command line).
sudo port selfupdate
sudo port install gnuplot
Now that will install the library into /opt/local/lib with the include files in /opt/local/include, so now just add that library to your Xcode project. Select the target and in the Build Phases tab open up the Link Binary With Libraries and press the + button and select Add Other. Now find /opt/local/lib/libgnuplot.a (I am assuming that's what it's called; I don't have it installed my self):
Now add /opt/local/include to your Header Search Paths so the compiler can find the gnuplot header files. Select the target and in Build Setting type in "header search" in the search box. Now double-click on the Header Search Path in the target column (or the project column to the right) and add /opt/local/include:
It's fine! You're learning then! Keep up! When I hit this kind of problem you may want to learn about the basis for linux gcc/g++ compilation and linking processes. Then you should learn Cmake and Automake, which are basically packages to configure projects before compiling building.
A typical (good) project in Unix systems build with commands
./configure
make
sudo make install
or
cmake CMakelists.txt
make all
sudo make install
That's what you need to do after downloading a source tarball online to install unix programs.
Now since you are using Mac, there are so-called package installers, one which is macports and homebrew. I personally suggest homebrew than macports here (I've tried both, although macports still outnumber homebrew with the number of repos, homebrew has the newest support, especially when upgrading to a new OS). So to install homebrew you can do
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Execute that in your terminal (see http://brew.sh/) for more information.
Then you could simply install GNUplot by
brew install gnuplot

program g++ not found in path

I am using Eclipse for a C project. I created a new Project by going to New->C project->Executable->Empty Project, Linux gcc toolchain.
When I add a new .c file, I get "program 'g++' not found in path".
How do I get rid of this? I'm not even using C++.
I had similar problem and it is solved by
Installing g++ The GNU C++ complier using ubuntu software centre and
Changing in -
Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build in Complier Settings [Shared]
From: ${COMMAND} -E -P -v -dD "${INPUTS}"
To : /usr/bin/${COMMAND} -E -P -v -dD "${INPUTS}"
I hope it helps.
For posterity I'm going to post my own solution to this problem. None of the answers above or on related StackOverflow questions helped; most referred to menu entries that didn't exist, and the ones I could try did nothing. I searched other sites as well; there were about 6 different answers repeated many times, and none helped.
Short answer: I blew away the Eclipse install and replaced it. Then it worked. For me at least it wasn't a project or configuration option (at least not one I could get to from the GUI); something in the Eclipse program folder had gotten tweaked and only a new install could repair the problem.
I'm doing Android development using the "ADT" (Android Developer Tools) build of Eclipse. I did something to the configuration that made it start giving the above error (actually two errors, for gcc and g++ both). And I tried plenty of potential solutions (in addition to my own searching for options that might help) with no success.
Thing is, I didn't NEED gcc or g++ in the path. I'm doing Android development, and while both are used in the build process, I'm not using Eclipse to do the builds; I use the Android build system. And the C/C++ Build/Discovery options didn't even give me an option for setting paths for gcc or g++. Other answers I found elsewhere referenced menu entries that don't exist, and most seemed to be about helping people to use the normal C/C++ build within Eclipse, which I didn't need to do.
So I used this opportunity to download the latest ADT package from Google, and then I ran the new one, importing the existing project into a new workspace (just in case the old workspace was corrupted or otherwise part of the problem). No more annoying gcc/g++ error.
I got the same error while I was using "Eclipse IDE for C/C++ Developers."
Install Eclipse from Ubuntu Software Center and then download and install Eclipse CDT.
To install CDT, open Eclipse -> Help -> Install New Software -> Add -> Archieve...
Then give CDT path to there. That's all
I was able to fix the problem by selecting
project(right click in Project Explorer on your project)->properties->Tool Chain Editor
and switching the Current Toolchain: to Android GCC and Current Buolder: to Android Builder
I also had the same problem. I did not have this error running my program but after a adding, including different Api and paths , probably unintentionally some changes happened in my Path that I could not fix it.
I could fix this error by going to Properties and just restore default for all the Tabs.

Any possible way to use Tokyo Cabinet in Eclipse?

Just spend 3 straight hours trying to solve the java.lang.UnsatisfiedLinkError: no jtokyocabinet in java.library.path problem in Eclipse in Linux.
Downloaded TC and TC-Java sources,
Built them both using ./config --prefix=/usr (so everything "JNI" related should be in /usr/lib)
Set the LD_LIBRARY_PATH=/usr/lib and CLASSPATH="$CLASSPATH:/usr/local/lib/tokyocabinet.jar" and exported both in .profile
Imported tokyocabinet.jar into the project.
Am I missing a setting other than the proper -Djava.library.path=. settings? I can't even find anything on the net about jtokyocabinet on the web or in the documentation. What's the secret sauce to getting this thing to work?
try to make a link to libjtokyocabinet.so...0 in your JAVA_HOME/jre/lib/i386.
it is because your code can not find tokyocabinet's *.so and *.a files, usually they are in /usr/local/lib, run the following command:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
and then try your code again.
Have the same problem, in my case, using OpenSUSE 12.3 64 bits and Eclipse.
First, the kyotocabinet-java package can be downloaded from this repository:
http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_12.3/
This package provide /usr/lib64/libjkyotocabinet.so.1.1.0 that is the library used by the kyotocabinet jar you can get from maven or the official site.
Looking for this lib I found that there is created a slink:
xxxx#xxxx:/usr/lib64> ls -al /usr/lib64/libjkyoto*
/usr/lib64/libjkyotocabinet.so.1 -> libjkyotocabinet.so.1.1.0
/usr/lib64/libjkyotocabinet.so.1.1.0
I just created a new slink without the ".1" at the end...
sudo ln -s libjkyotocabinet.so.1.1.0 libjkyotocabinet.so
/usr/lib64/libjkyotocabinet.so -> /usr/lib64/libjkyotocabinet.so.1.1.0
And all worked alright, seems that
System.loadLibrary("jkyotocabinet");
don't work if the library name is ended with something different to ".so"
Yes, you're missing something. Eclipse controls its own classpath, so whatever you set up in the environment outside Eclipse is likely not to have any effect.
You need to go into the properties for your project, find the "Build Path" settings and add the path to your tc.jar (or jars) to your build path there.
It may be easier to set up a /lib directory within your eclipse project, copy your tokyo jar there and add that to your build path. That way, it becomes part of your project (and can move from Eclipse installation to Eclipse installation) rather than being an external system dependency.

Resources