How to install PCAP for ruby on Windows - ruby

This must be a relatively newb question but I am still stuck. I know there is a simple solution to this. I've done some googling but could not find an exact answer. Here is the error I get...
C:\Ruby193\include\ruby-1.9.1\i386-mingw32>gem install pcap
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcap:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lxnet... no
checking for hstrerror()... no
checking for pcap.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Clearly I am missing some libraries but I not know how to get these nor do I know where they should be located when attempting to install pcap.
mkmf.log
have_library: checking for socket() in -lsocket... -------------------- no
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lshell32 -lws2_32 -limagehlp "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: int main() {return 0;}
/* end */
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lsocket -lshell32 -lws2_32 -limagehlp "
c:/users/user/downloads/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lsocket
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { void ((*volatile p)()); p = (void ((*)()))socket; return 0; }
/* end */
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lsocket -lshell32 -lws2_32 -limagehlp "
conftest.c: In function 't':
conftest.c:8:1: error: too few arguments to function 'socket'
c:\users\user\downloads\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:553:35: note: declared here
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { socket(); return 0; }
/* end */
--------------------
have_library: checking for gethostbyname() in -lxnet... -------------------- no
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lxnet -lshell32 -lws2_32 -limagehlp "
c:/users/user/downloads/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lxnet
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { void ((*volatile p)()); p = (void ((*)()))gethostbyname; return 0; }
/* end */
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lxnet -lshell32 -lws2_32 -limagehlp "
conftest.c: In function 't':
conftest.c:8:1: error: too few arguments to function 'gethostbyname'
c:\users\user\downloads\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:555:57: note: declared here
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { gethostbyname(); return 0; }
/* end */
--------------------
have_func: checking for hstrerror()... -------------------- no
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lshell32 -lws2_32 -limagehlp "
conftest.c: In function 't':
conftest.c:8:53: error: 'hstrerror' undeclared (first use in this function)
conftest.c:8:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { void ((*volatile p)()); p = (void ((*)()))hstrerror; return 0; }
/* end */
"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -L. -LC:/Ruby193/lib -L/usr/local/lib -lmsvcrt-ruby191 -lshell32 -lws2_32 -limagehlp "
C:\Users\USER\AppData\Local\Temp\ccbjKHSc.o:conftest.c:(.text+0x19): undefined reference to `hstrerror'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5:
6: /*top*/
7: int main() {return 0;}
8: int t() { hstrerror(); return 0; }
/* end */
--------------------
have_header: checking for pcap.h... -------------------- no
"gcc -E -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -I/usr/local/include conftest.c -o conftest.i"
conftest.c:5:18: fatal error: pcap.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: #include <pcap.h>
/* end */
--------------------

The end solution was to not use pcap rub which seems to be fairly outdated.
I tried PCAP rub and continued to run into issues. You can follow the thread here where Jonm ultimately helped me to get up and running.

Related

Cannot link dlfcn functions with gcc and -ldl

I am trying to use functions in dlcfn.h, to print custom trace from my C application.
I do link with -ldl, yet the linker complains that it cannot find dladdr().
What am I missing?
Here is an example, inst.c:
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
__attribute__((no_instrument_function))
void __cyg_profile_func_enter (void *this_fn, void *call_site) {
printf("%p\n", this_fn);
Dl_info info;
if (dladdr(this_fn, &info)) {
printf("%p [%s] %s\n",
this_fn,
info.dli_fname ? info.dli_fname : "?",
info.dli_sname ? info.dli_sname : "?");
}
}
__attribute__((no_instrument_function))
void __cyg_profile_func_exit (void *this_fn, void *call_site) {
}
void my_function_b(void)
{
printf("b!\n");
}
void my_function_a(void)
{
printf("a!\n");
my_function_b();
}
int main(void)
{
my_function_a();
my_function_b();
return 0;
}
And a Makefile:
CFLAGS += -O0 -g -finstrument-functions -rdynamic -ldl
inst: inst.c
gcc $(CFLAGS) $^ -o $#
The result:
$ make
gcc -O0 -g -finstrument-functions -ldl inst.c -o inst
/usr/bin/ld: /tmp/ccKL1sh2.o: in function `__cyg_profile_func_enter':
/home/gauthier/tmp/inst/inst.c:12: undefined reference to `dladdr'
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: inst] Error 1
You should put libraries after source or object files which import their functions, otherwise linker will optimize them out:
gcc -O0 -g -finstrument-functions inst.c -ldl -o inst

Undefined reference to sequence when trying to input a vector

This seems a simple but somehow the compile sends this error message which I'm not able understand thus correct my code.
This is a simplified version of what I did, just so it can appear the error for you:
Main.cpp
include "myfunction.h"
int main(){
std::vector<int> myVet = {1,4,3};
sequence(1,2,1,myVet);
}
myfunction.h
#include <vector>
/*funtion creates a sequence*/
void sequence(int start, int end,
int step, std::vector<int> skip);
myfunction.cpp
#include "myfunction.h"
void sequence(int start, int end,
int step, std::vector<int> skip){
auto x = 0;
};
This gives me an error message which says
In function 'main':
/home/machina/Documents/Grafos&Redes/Implementação/main.cpp:18: undefined reference to 'sequence(int, int, int, std::vector <int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status
Could you please explain me why it appears?
This is the following command which I've been using for compiling
g++ -std=c++11 -g -Wall -Wextra -Werror main.cpp -o main.out
You are only passing main.cpp to g++.
g++ needs to know about myfunction.cpp where your function is defined so as to compile and link it to your program.
The command to use should be:
g++ -std=c++11 -g -Wall -Wextra -Werror main.cpp myfunction.cpp -o main.out

what is the gcc option for add header file in complie time?

How to compile this code?
/* main.c file*/
#include <stdio.h>
int main(void)
{
int c;
c = add(5,5);
printf("sum is %d\n",c);
return 0;
}
Add.c(in same directory)
/*add.c*/
int add(int a, int b)
{
int c;
c = a + b;
return c;
}
Add.h(in same directory)
/* add.h file*/
int add(int, int);
Then i am create a object file for add.c
$ gcc -c -Wall add.c -I.
Then i am try to create a object file for main.c
$ gcc -c -Wall main.c -I.
main.c:6:2: warning: implicit declaration of function ‘add’ [-Wimplicit-function-declaration]
c = add(5, 5);
^
Please any one tell, how to give the headfile name in compiling time.
you can either use #include "Add.h" at the top of your main.c (this is the preferred route), or you can use the -include command line flag (this is discouraged because it does not scale and is not portable):
gcc -c -Wall main.c -I. -include Add.h

Every time I upgrade Xcode, I get linker errors with brew installed GCC

So, I upgraded to Mavericks as well as the newest version of Xcode (5.02), and — as expected, was unable to compile any new Ruby gems which include C extensions. This happens specifically with my own project, NMatrix, which includes C and C++ code.
I reinstalled the command line tools for Xcode. Then I upgraded homebrew. Then I uninstalled rbenv, ruby-build, and my custom GCC versions (except for 4.7, which was installed manually rather than through brew).
Next, I used brew to install gcc48 (and gcc49 for good measure). I instructed my gem to build with GCC-4.8.2 rather than the dev snapshot of GCC 4.9.
The good news is that my gem now compiles properly. The bad news is that it won't link. Here is just the linking step:
$ bundle exec rake compile
cd tmp/x86_64-darwin13.0.0/nmatrix/2.0.0
make
linking shared-object nmatrix.bundle
ld: warning: directory not found for option '-L/usr/lib64/atlas'
0 0x10ef3f724 __assert_rtn + 144
1 0x10ef7425e archive::File<x86_64>::makeObjectFileForMember(archive::File<x86_64>::Entry const*) const + 1118
2 0x10ef73c3b archive::File<x86_64>::justInTimeforEachAtom(char const*, ld::File::AtomHandler&) const + 139
3 0x10ef883fe ld::tool::InputFiles::searchLibraries(char const*, bool, bool, bool, ld::File::AtomHandler&) const + 210
4 0x10ef8f181 ld::tool::Resolver::resolveUndefines() + 189
5 0x10ef911a5 ld::tool::Resolver::resolve() + 79
6 0x10ef3fb17 main + 669
A linker snapshot was created at:
/tmp/nmatrix.bundle-2013-10-15-085036.ld-snapshot
ld: Assertion failed: (memberIndex != 0), function makeObjectFileForMember, file /SourceCache/ld64/ld64-224.1/src/ld/parsers/archive_file.cpp, line 355.
collect2: error: ld returned 1 exit status
make: *** [nmatrix.bundle] Error 1
rake aborted!
Command failed with status (2): [make...]
This is weird for a couple of reasons.
It's a sporadic error. We've seen it a couple of times and it always seems to go away for reasons that are unclear.
I don't think the ld: warning line is relevant, but it might be. ATLAS is provided by Xcode's Accelerate framework, and in the current version of Xcode, it no longer seems to be at /usr/lib64/atlas (or maybe it never was). That path is only one of the possible installation locations, and the correct path (/usr/local/atlas) is properly included.
When I search for the function prototypes given above, I see a lot of LLVM stuff. It's all Mac OS X errors. So this is Mac-specific. But why would it be using LLVM at all when I'm providing the GCC? Is it using the correct version of GCC for compilation but trying to link with the wrong version?
The last is probably the best hypothesis. It seems like this error only shows up on computers where you can't override the default GCC installation (Macs, namely).
I can't install a new ATLAS because there's no known way to turn off throttling on a MacBook Air — a prerequisite for ATLAS installation, so I can't eliminate the ld warning.
Does anyone have any thoughts as to what these errors might mean? Compiler/linker gurus? Anyone?
Update
It occurred to me to look in mkmf.log, and I found some additional information. Sure enough, it's an ATLAS problem. But I'm not really sure why it's only looking in the one directory.
ld: warning: directory not found for option '-L/usr/lib64/atlas'
Undefined symbols for architecture x86_64:
"_ATL_dgemm", referenced from:
_cblas_dgemm in libcblas.a(cblas_dgemm.o)
"_ATL_dsyreflect", referenced from:
_cblas_dgemm in libcblas.a(cblas_dgemm.o)
"_ATL_dsyrk", referenced from:
_cblas_dgemm in libcblas.a(cblas_dgemm.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <cblas.h>
4:
5: /*top*/
6: extern int t(void);
7: int t(void) { void ((*volatile p)()); p = (void ((*)()))cblas_dgemm; return 0; }
8: int main(int argc, char **argv)
9: {
10: if (argc > 1000000) {
11: printf("%p", &t);
12: }
13:
14: return 0;
15: }
/* end */
"gcc -o conftest -I/Users/jwoods/.rbenv/versions/2.0.0-p247/include/ruby-2.0.0/x86_64-darwin13.0.0 -I/Users/jwoods/.rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby/backward -I/Users/jwoods/.rbenv/versions/2.0.0-p247/include/ruby-2.0.0 -I../../../../ext/nmatrix -I/usr/local/atlas/include -I/usr/include/atlas -Wall -Werror=return-type -I/Users/jwoods/.rbenv/versions/2.0.0-p247/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -Wall -Werror=return-type -O3 -Wno-error=shorten-64-to-32 -pipe conftest.c -L. -L/Users/jwoods/.rbenv/versions/2.0.0-p247/lib -L/usr/local/atlas/lib -L/usr/local/lib -L/usr/lib -L/usr/lib64/atlas -L. -L/Users/jwoods/.rbenv/versions/2.0.0-p247/lib -L/usr/local/lib -lcblas -llapack -lruby-static -lcblas -llapack -lpthread -ldl -lobjc "
conftest.c:7:27: error: too few arguments to function call, expected 14, have 0
int t(void) { cblas_dgemm(); return 0; }
~~~~~~~~~~~ ^
/usr/local/atlas/include/cblas.h:470:1: note: 'cblas_dgemm' declared here
void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <cblas.h>
4:
5: /*top*/
6: extern int t(void);
7: int t(void) { cblas_dgemm(); return 0; }
8: int main(int argc, char **argv)
9: {
10: if (argc > 1000000) {
11: printf("%p", &t);
12: }
13:
14: return 0;
15: }
/* end */
I believe I found an answer. One of the lib search directories in the extconf.rb (which generates the Makefile) was /usr/lib64/, which doesn't exist on the system. So once I removed that from the search path, it compiled and linked properly.
I also added an entry to the $libs definition which may or may not have been useful.
It went from being $libs += " -llapack -lcblas -latlas " to:
$libs += " -llapack -lclapack -lcblas -latlas "
But that last bit solved issues after linking, not during.

GCC Creating new PASS

I am trying to write a new GCC pass in gcc-4.1.2. This is my first attempt and I am trying to print lines of code for a function gcc is compiling. So I added the below code. Note if I remove code in execute_gimple_manipulation method the issue does not occur :
gcc/gcc-4.1.2 1223> cat gcc/gimple-manipulation.c
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "ggc.h"
#include "flags.h"
#include "tree.h"
#include "basic-block.h"
#include "tree-flow.h"
#include "tree-pass.h"
#include "tree-dump.h"
#include "timevar.h"
#include "diagnostic.h"
#include "cfgloop.h"
#include "tree-scalar-evolution.h"
#include "tree-ssa-propagate.h"
#include "tree-chrec.h"
static void execute_gimple_manipulation (void);
static bool gate_gimple_manipulation (void);
/*-------------------------
The main driver function.
-------------------------*/
static void execute_gimple_manipulation (void)
{
basic_block bb = ENTRY_BLOCK_PTR;
int bbcounter=0, stmtcounter;
tree stmt;
block_stmt_iterator si;
/* traverse each basic block and print all statements */
FOR_EACH_BB (bb){ /* in any order */
bbcounter++;
printf("\n-> entering bb # %d (internal #: %d)\n", bbcounter, bb->index);
stmtcounter=0;
for(si = bsi_start(bb); !bsi_end_p(si); bsi_next(&si)){
stmtcounter++;
printf(" encountering statement #%2d: ", stmtcounter);
stmt = bsi_stmt(si);
print_generic_stmt (stderr, stmt, 0);
}
}
}
/* ------------------------------------------
Return true if we should execute our pass.
------------------------------------------*/
static bool
gate_gimple_manipulation (void)
{
/* return (flag_unit_at_a_time != 0 && flag_ipa_gimple_manipulation
Don't bother doing anything if the program has errors.
&& !(errorcount || sorrycount));*/
return (/*optimize >= 1*/
/* Don't bother doing anything if the program has errors. */
/*&&*/ !(errorcount || sorrycount));
}
struct tree_opt_pass pass_gimple_manipulation =
{
"gm_pass_simple", /* name */
gate_gimple_manipulation, /* gate */
execute_gimple_manipulation, /* execute */
NULL, /* sub */
NULL, /* next */
0, /* static pass number */
0, /* tv_id */
PROP_cfg | PROP_ssa | PROP_alias, /* properties required */
0, /* properties provided */
0, /* properties destroyed */
0, /* todo_flags start */
TODO_dump_func, /* todo_flags finish */
0 /* letter */
};
My new code compilation goes fine as per make:
gcc -c -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros -Wold-style-definition -Wmissing-format-attribute -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include ../.././gcc/gimple-manipulation.c -o gimple-manipulation.o
But the compilation process fails further on:
gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/xgcc -Bgcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -msse -c \
../.././gcc/config/i386/crtfastmath.c \
-o crtfastmath.o
../.././gcc/config/i386/crtfastmath.c:110: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [crtfastmath.o] Error 1
make[2]: Leaving directory `gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc'
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory `gcc/gcc-4.1.2'
make: *** [all] Error 2
gcc/gcc-4.1.2 1223>
Any help – why the issue is occurring and how can I achieve the objective?

Resources