Subject: CGAL users discussion list
List archive
- From: Laurent Saboret <>
- To:
- Subject: Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3
- Date: Thu, 07 Jun 2007 13:30:17 +0200
- Organization: INRIA Sophia-Antipolis
Dear Kevin Kai Xu,
You found a bug in CGAL's Taucs_fix.h :
I was able to reproduce the bug by including this header in 2 .cpp files.
Functions defined in this file are copies of TAUCS functions with bug fixes. In a header file, they should be marked "inline".
Just drop the attached file in CGAL-3.3\include\CGAL.
Sorry for the inconvenience,
Laurent Saboret
INRIA Sophia-Antipolis
a écrit :
I am migrating my project (VC++ .NET 2003) from CGAL3.2.1 to CGAL3.3.// Copyright (c) 2005 INRIA (France).
When I rebuild my project(using taucs libs packaged in CGAL) on the new CGAL,
the linker complained that there are redefinitions of
_cgal_taucs_available_memory_size:
Mesh.obj : error LNK2005: _cgal_taucs_available_memory_size already defined
in ChildFrm.obj
MeshDoc.obj : error LNK2005: _cgal_taucs_available_memory_size already
defined in ChildFrm.obj
MeshView.obj : error LNK2005: _cgal_taucs_available_memory_size already
defined in ChildFrm.obj
FormView.obj : error LNK2005: _cgal_taucs_available_memory_size already
defined in ChildFrm.obj
Even though I just include the "Taucs_solver_traits.h" in the
enrich_polygon.h, (included by MeshDoc.h, while MeshDoc.h is included by other .cpp)
and do nothing, the link errors still appear! But the same project can be compiled and
linked without error when built with CGAL3.2.1!
The new CGAL provides the auto-link mechanism for libraries, including taucs.
Does the problem have something to do with the auto-link? How do I get rid of
the link errors?
Thank you!
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the
software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL:
svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Surface_mesh_parameterization/include/CGAL/Taucs_fix.h
$
// $Id: Taucs_fix.h 38842 2007-05-24 14:52:02Z lsaboret $
//
//
// Author(s) : Laurent Saboret, Pierre Alliez, Bruno Levy
#ifndef CGAL_TAUCS_FIX
#define CGAL_TAUCS_FIX
// Include TAUCS main header taucs.h
#ifndef CGAL_INCLUDED_TAUCS_H
#define CGAL_INCLUDED_TAUCS_H
// GCC 3.x does not compile if we include complex.h within "extern C {}"
// and complains that this header is deprecated.
#if defined(__GNUC__)
#undef __DEPRECATED
#include <complex.h>
#endif
// taucs.h will define min/max macros if it's not already done (e.g. by
Windows.h).
#ifndef min
#define CGAL_TAUCS_DEFINES_MIN
#endif
#ifndef max
#define CGAL_TAUCS_DEFINES_MAX
#endif
// TAUCS is a C library
extern "C" {
#include <taucs.h>
}
// Undefine Taucs' min/max macros to avoid an error
// with std::min()/std::max() calls in standard C++ headers.
#ifdef CGAL_TAUCS_DEFINES_MIN
#undef min
#endif
#ifdef CGAL_TAUCS_DEFINES_MAX
#undef max
#endif
#endif
#ifdef OSTYPE_linux
#include <unistd.h>
#include <math.h>
#endif
extern "C"
{
/********************************************************************/
/* FIX OF taucs_system_memory_size() */
/* returns size of memory reported by the operating system */
/* should not normally be called by the user (call _avail_) */
/* (see taucs_memory.c) */
/********************************************************************/
#ifdef OSTYPE_linux
/* Redirect call to avoid link error */
#define taucs_system_memory_size cgal_taucs_system_memory_size
inline double taucs_system_memory_size()
{
/* LS 2006: The original code below is buggy on Linux 2.6 */
/* (because /proc/meminfo format changed) */
#if 0
FILE* f;
double m;
double m_sc;
m_sc = (double) sysconf(_SC_PAGESIZE);
m_sc *= (double) sysconf(_SC_PHYS_PAGES);
/* total memory is the first number in /proc/meminfo */
f = fopen("/proc/meminfo","r");
if (f==NULL) return m_sc;
if (fscanf(f,"%*[a-zA-Z :\n\r]%lf",&m) != 1) return m_sc;
if (m != m_sc) {
taucs_printf("Warning: /proc/meminfo reports %lfMB of memory while\n",
m/1048576.0);
taucs_printf(" sysconf reports %lfMB of memory\n",
m_sc/1048576.0);
}
return m;
#endif
/* LS 2006: fix */
double m_sc;
m_sc = (double) sysconf(_SC_PAGESIZE);
m_sc *= (double) sysconf(_SC_PHYS_PAGES);
return m_sc;
}
#endif
/* LS 2007: Cygwin implementation */
#ifdef OSTYPE_cygwin
/* Redirect call to avoid link error */
#define taucs_system_memory_size cgal_taucs_system_memory_size
inline double taucs_system_memory_size()
{
double m_sc;
m_sc = (double) 4096; /* page size */
m_sc *= (double) sysconf(_SC_PHYS_PAGES);
return m_sc;
}
#endif
/********************************************************************/
/* FIX OF taucs_available_memory_size() */
/* returns size of memory available for allocation */
/* (see taucs_memory.c) */
/********************************************************************/
/* Redirect calls to avoid link error */
#define taucs_available_memory_size cgal_taucs_available_memory_size
#define taucs_malloc malloc
#define taucs_free(ptr) if (ptr != NULL) free(ptr)
/* LS 2007: if m_sys is meaningful, then we limit malloc test by 0.75*m_sys */
#define limit_memory(mem) ((mem) < m_max ? (mem) : m_max)
inline double taucs_available_memory_size()
{
/* LS 2007: The original code below creates an infinite loop on Linux */
/* (optimistic memory allocation => malloc() never returns NULL) */
#ifndef OSTYPE_linux
double m_sys;
double m,m_low,m_high,m_tol;
char* p;
double m_max;
m_sys = taucs_system_memory_size();
/* LS 2007: if m_sys is meaningful, then we limit malloc test by 0.75*m_sys
*/
if (m_sys > 0)
m_max = floor(0.75 * m_sys);
else
m_max = DBL_MAX;
/* malloc test */
m = 1048576.0;
while ( (m < m_max-1) /* m_max not reached */
&& ((p=(char*) taucs_malloc( (size_t) limit_memory(m*2.0) )) != NULL)
) {
taucs_printf("taucs_avail_memory_size: %.0lf Mb\n", limit_memory(m*2.0) /
1048576.0);
taucs_free(p);
m = limit_memory(m*2.0);
}
m_low = m;
m_high = limit_memory(m*2.0);
m_tol = m / 128.0;
while ( m_high - m_low > m_tol ) {
m = m_low + ( (m_high-m_low)/2.0 );
taucs_printf("taucs_avail_memory_size: [%.0lf %.0lf %.0lf]\n",
m_low / 1048576.0,
m / 1048576.0,
m_high / 1048576.0);
if ( (p=(char*) taucs_malloc( (size_t) m )) != NULL )
m_low = m;
else
m_high = m;
taucs_free(p);
}
m = m_low;
taucs_printf("taucs_avail_memory_size: malloc test=%.0lf MB sys test=%.0lf
MB\n",
m / 1048576.0,
m_sys / 1048576.0
);
return m;
#else /* LS 2007: workaround Linux optimistic memory allocation */
double m_sys; /* size of physical memory */
double m; /* size of memory available for allocation */
m_sys = (double) sysconf(_SC_PAGESIZE);
m_sys *= (double) sysconf(_SC_PHYS_PAGES);
/* we limit m by 0.75*m_sys */
m = floor(0.75 * m_sys);
taucs_printf((char*)"taucs_available_memory_size returns %lfMB\n",
m/1048576.0);
return m;
#endif
}
} // extern "C"
#endif // CGAL_TAUCS_FIX
- About auto-link TAUCS in CGAL3.3, kevin . kai . xu, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Fernando Cacciola, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Sylvain Pion, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Fernando Cacciola, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Sylvain Pion, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Laurent Saboret, 06/07/2007
- Re: [cgal-discuss] About auto-link TAUCS in CGAL3.3, Fernando Cacciola, 06/07/2007
Archive powered by MHonArc 2.6.16.